Skip to content
Advertisement

Open a file’s properties window using Java

This is a question only regarding Java in Windows.

I need a method that will call this window:

enter image description here

So essentially the method should be something like:

public void openProperties(File file){ // or String fileName

}

So the statement: opernProperties(new File(test.txt)); should open the above window.

So just to clarify, I do not want to read and manage the properties. I just want to open the properties window.

Advertisement

Answer

I was able to display the file properties window using the following:

This should display the properties window with a delay of 3 seconds. Notice that alk talked about passing the window through hwnd member if you don’t want it to auto close after the 3 seconds

public static void main(String[] args) throws InterruptedException {
        ShellAPI.SHELLEXECUTEINFO shellExecuteInfo = new ShellAPI.SHELLEXECUTEINFO();
        shellExecuteInfo.lpFile = "C:\setup.log";
        shellExecuteInfo.nShow = User32.SW_SHOW;
        shellExecuteInfo.fMask = 0x0000000C;
        shellExecuteInfo.lpVerb = "properties";
        if (Shell32.INSTANCE.ShellExecuteEx(shellExecuteInfo)){
            Thread.sleep(3000);
        }
    }
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement