问题描述
下面的一个用于从windows获取进程列表
Below one is used for get list of processes from the windows
Process proc = Runtime.getRuntime().exec ("tasklist.exe");
但我想获取应用程序标签内容本身我需要一个解决方案
But I want to get the application tab content itselfi need a solution for this
Process proc = Runtime.getRuntime().exec ( ? ? ?);
推荐答案
我正在尝试给出答案,即使帖子已经超过一年了.
I am trying to give the answer, even if the post is already more than one year old.
尝试使用以下代码片段:
Try with the following code snippet:
private static final String STR_MATCH = "My Java Application";
String strProcess;
BufferedReader input = null;
try {
if(System.getProperty("os.name").startsWith("Windows")) {
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe /v /FI \"STATUS eq RUNNING\" /FI \"imagename eq javaw.exe\"");
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((strProcess = input.readLine()) != null) {
if(strProcess.contains(STR_MATCH))
/* lot of code here */
}
// Close resources
input.close();
}
catch(IOEXception ioe) {
/* handle exception */
}
这里需要注意的是获取Process p
的方式,即:
The thing to notice here is the way used to get the Process p
, i.e.:
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe /v /FI \"STATUS eq RUNNING\" /FI \"imagename eq javaw.exe\"");
调用 tasklist.exe
时添加的过滤器 /FI "STATUS eq RUNNING"/FI "imagename eq javaw.exe"
允许获取更多相关信息到进程 javaw.exe
,包括窗口/应用程序名称.
The filter /FI "STATUS eq RUNNING" /FI "imagename eq javaw.exe"
that has been added when invoking tasklist.exe
allows to get more information related to the process javaw.exe
, including the Window/Application name.
这篇关于如何使用java代码在windows中打开应用程序(任务管理器->应用程序选项卡内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!