duka.milan duka.milan - 1 year ago 128
Java Question

check if some exe program is running on the windows

How to check if some .exe program is running (is in process) on Windows?

I'm making java application which update one .exe program. So, if that exe program is used by some client, my application ask for closing exe program, and after closing automatically replace .exe file with new one.

Answer Source

You can run the following statement in your java program : Before that you need to know the name of the task in task manager. Say you want to see MS-Word is running. Then run MS-Word, goto task manager and under the process tab, you should see a process named word.exe. Figure out the name for the process you are targetting. Once you have that , you just run the following code: String line;

String line;
String pidInfo ="";

Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");

BufferedReader input =  new BufferedReader(new InputStreamReader(p.getInputStream()));

while ((line = input.readLine()) != null) {


if(pidInfo.contains("your process name"))
    // do what you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download