I would like my java program to check whether another instance of it is already running, and kill it if this is the case (on a Windows platform). I'm doing this with the code
String CMD =
"wmic PROCESS where \"CommandLine like '%%MyProgram%%'\" Call Terminate";
Process process = Runtime.getRuntime().exec(CMD);
The code executes succesfully and kills the running program if it is found, however once executed it forces also the calling program to exit (there must be some hidden call to System.exit()). Is there a way for executing the command without exiting the calling program?