'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.



Solution 1:[1]

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);
        }
    }

Solution 2:[2]

The Windows API call SHObjectProperties will also launch Windows file property dialog. You could call from JNA, JNI or try JDK Panama / Foreign Memory API available as incubator in JDK16 or above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tzach Solomon
Solution 2