这是我非常想要的快照!

我正在尝试开发一个java程序,可以得到所有打开的任务栏中的应用程序。我尝试了许多链接,但没有一个对我有帮助。Ganesh Rangarajan in July 2013也问了同样的问题,但没有人回答他。这是他的question。
发布于 2016-05-14 20:28:29
这个回复对你来说太晚了,但可能会帮助正在面临类似问题的其他人。
我只是写了一个类似的应用程序来做这件事,但只能打开CMD
并且您可以将listCommand替换为
powershell -command "get-Process | format-table mainwindowtitle"(注意在java中使用它)来获取所有打开的应用程序。
public String[] getEnginesFromTaskManger()
{
// listCommand is a command to get all opened CMD program like (batches,.......)
// you can test it in your CMD as powershell -command "get-Process cmd | format-table mainwindowtitle"
String listCommand = "powershell -command \"get-Process cmd | format-table mainwindowtitle\"";
try
{
String line;
// since line length for powershell output is 79
int outLen = 79;
Process p = Runtime.getRuntime().exec(listCommand);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
line = input.readLine();
System.out.println("line: " + line + "\t" + line.length());
EnginesListFromTaskManeger = new ArrayList<String>();
int i = 0;
/*
I used this outLen > 0 condition to make sure that this method will close automatically
in case of no running CMD applications and you running this from your IDE's (Eclipse, Netbeans , ......)
the powershell will not stopped so i used it. */
while(line != null && outLen > 0)
{
System.out.println("line: " + line + "\t" + line.length());
line = input.readLine().trim().toLowerCase();
outLen = line.length();
EnginesListFromTaskManeger.add(i, line);
System.out.println(EnginesListFromTaskManeger.get(i));
// EnginesListFromTaskManeger[i]=(String)input.readLine().trim();
// System.out.println("EnginesListFromTaskManeger"+ EnginesListFromTaskManeger[i]);
i++;
}
input.close();
}catch(Exception err)
{
err.printStackTrace();
}
ListFromTaskManeger = new String[EnginesListFromTaskManeger.size()];
ListFromTaskManeger = EnginesListFromTaskManeger.toArray(ListFromTaskManeger);
return ListFromTaskManeger;
}https://stackoverflow.com/questions/35956816
复制相似问题