views:

2624

answers:

6

Hi,

I need a Java way to find a running Win process from which I know to name of the executable. I want to look whether it is running right now and I need a way to kill the process if I found it.

Thank you! Greetz, GHad

A: 

You cannot call windows APIs from Java, you'll have to use for example native C++ code and JNI to do that.

auramo
A: 

You will have to call some native code, since IMHO there is no library that does it. Since JNI is cumbersome and hard you might try to use JNA (Java Native Access). https://jna.dev.java.net/

jb
+2  A: 

You could use a command line tool for killing processes like SysInternals PsKill and SysInternals PsList.

You could also use the build-in tasklist.exe and taskkill.exe, but those are only available on Windows XP Professional and later (not in the Home Edition).

Use java.lang.Runtime.exec to execute the program.

arturh
+5  A: 

You can use command line windows tools "tasklist" and "taskkill" and call them from Java using "Runtime.exec()".

+1  A: 

Thanks for suggestions. Meanwhile I found a little XP tool called "tasklist.exe" that i can call with Runtime.exec. It would report back all running processes. In combination with PsKill I think I will master this task. Thanks to arturh

GHad
+1  A: 

There is a little API providing the desired functionality:

https://winp.dev.java.net/

Windows Process Library

Daniel Lindner