1

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?

Rex
  • 801
  • 1
  • 17
  • 26
  • 1
    http://stackoverflow.com/questions/62418/knowing-which-java-exe-process-to-kill-on-a-windows-machine – Joop Eggen Dec 08 '11 at 14:41
  • It is a pity you did not choose [JWS](http://stackoverflow.com/tags/java-web-start/info) to launch the app., it has the [`SingleInstanceService`](http://pscode.org/jws/api.html#sis) built in. *"The `SingleInstanceService` ensures there is only one version of an application on-screen at any given moment. If the user opens the program while an instance is already on-screen, the application's notification method is called, and the developer gets to decide what action needs to be taken.. "* Of course, JWS also works on MacOS & *nix flavors for which there is a JRE. – Andrew Thompson Dec 08 '11 at 14:48
  • I can't do that, because the application being installed is massive and includes some windows software also to run (biometric hardware drivers). – Rex Dec 09 '11 at 12:13

2 Answers2

1

The command jps -v will give you the command line parameters to the running Java processes.

artbristol
  • 32,010
  • 5
  • 70
  • 103
  • Thanks, this is useful, though in my situation I can't assume that there's a JDK available to run this. The Java program I am trying to install bundles its own JRE. – Rex Dec 09 '11 at 07:23
1

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
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • I also looked at FindWindow, but it asks for a window class as a compulsory parameter, and window title as an optional parameter. This I assume is something at the Win32 level. I don't have Spy++ or anything that I can download (WinSpy++ for eg) that can tell me the windowclass of my Java app. Is there a standard name for that? – Rex Dec 09 '11 at 07:35