How to find and close running Win-Process which is Java app from within other Java app?

Viewed 54

There is windows process which is actually a java application (java.exe). I need to close it from within other java application (other running .jar) which is probably will also be named as java.exe in windows taskbar.

To do the task we would normally do it this way

Runtime.getRuntime().exec(KILL + serviceName); // where serviceName is a `java.exe`

But there would be some java.exe processes in windows taskbar. So how to find the one I need? In this case it is forum.jar.

Actually this jar was started from .bat file (if it makes any difference) - it is process.bat as it seen in the screenshot.

enter image description here

1 Answers

You could run

wmic process where caption="java.exe" get commandline,description,processid

to get the list of processes and their associated command line like in your screenshot. Then you get the ID of the command you want to kill and kill it with taskkill /pid xxx.

Related