如何通过Java检测特定进程是否在Windows下运行? [英] How to detect via Java whether a particular process is running under Windows?

查看:158
本文介绍了如何通过Java检测特定进程是否在Windows下运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个标题几乎总结了这个问题。我发现的唯一的事情是这个
但我不是确定这是否可行。

Well the title pretty much sums the question. The only thing I found is this but I'm not sure if thats the way to go.

推荐答案

您可以使用wmic实用程序检查正在运行的进程列表。

假设您要检查Windows的explorer.exe进程是否正在运行:

You can use the wmic utility to check the list of running processes.
Suppose you want to check if the windows' explorer.exe process is running :

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();
}

参见 http://ss64.com/nt/wmic.html http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp ,了解一下你可以从wmic获得的一些例子......

See http://ss64.com/nt/wmic.html or http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp for some example of what you can get from wmic...

这篇关于如何通过Java检测特定进程是否在Windows下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆