Search code examples
javawindowsnsis

Detecting an already running Java application from NSIS


Yes, it's well documented how to get the name of your application's exe file and see if it is running. When the application in question is a java application, the running exe will always be java.exe, and so this method falls flat on its face since there could be any number of java applications currently running, all launched with java.exe. Each one will differ in the commandline parameters passed, including the main class name.

I need to know the commandline parameters to java.exe so I can know that only the one that says java.exe MyProgram is to be terminated.

How do I do that in NSIS?


Solution

  • I use the FindWindow command. This assumes that the different Java applications have different window titles.

    Edited to add: While the window class is a required parameter, the empty string (any window class) is a valid window class parameter. Here's a complete FindWindow function from one of my NSIS installers:

    Function filzip_check
        filzip_check_start:
            ClearErrors
            FindWindow $5 "" "FilZip"
            StrCmp $5 "0" filzip_check_end +1
            MessageBox MB_OK "Please close any FilZip windows before continuing \
                    the install"
            Goto filzip_check_start
        filzip_check_end:
    FunctionEnd