如何通过Java检测特定进程是否在Windows下运行?

gmu*_*unk 9 java

好吧,标题几乎总结了这个问题.我发现的唯一的事情就是这个, 但我不确定这是不是这样.

Phi*_*ppe 12

您可以使用wmic实用程序检查正在运行的进程列表.
假设您要检查Windows的explorer.exe进程是否正在运行:

String line;
try {
    Process proc = Runtime.getRuntime().exec("wmic.exe");
    BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());
    oStream .write("process where name='explorer.exe'");
    oStream .flush();
    oStream .close();
    while ((line = input.readLine()) != null) {
        System.out.println(line);
    }
    input.close();
} catch (IOException ioe) {
    ioe.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

有关您可以从wmic获得的一些示例,请参阅http://ss64.com/nt/wmic.htmlhttp://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp ...