如何使用java代码在windows中打开应用程序(taskmanager->;应用程序选项卡内容)
下面一个用于从windows获取进程列表如何使用java代码在windows中打开应用程序(taskmanager->;应用程序选项卡内容),java,windows,Java,Windows,下面一个用于从windows获取进程列表 Process proc = Runtime.getRuntime().exec ("tasklist.exe"); 但我想获取应用程序选项卡内容本身 我需要一个解决方案 Process proc = Runtime.getRuntime().exec ( ? ? ?); 这是从命令“ps-e”解析进程列表的另一种方法: 无法获取应用程序,因为这只是此选项卡上显示的打开窗口。每个应用程序都是一个过程 你可以从c#试试这个: Open
Process proc = Runtime.getRuntime().exec ("tasklist.exe");
但我想获取应用程序选项卡内容本身
我需要一个解决方案
Process proc = Runtime.getRuntime().exec ( ? ? ?);
这是从命令“ps-e”解析进程列表的另一种方法: 无法获取应用程序,因为这只是此选项卡上显示的打开窗口。每个应用程序都是一个过程 你可以从c#试试这个: OpenWindowProcesss应该包含所有打开的应用程序,它们有一个活动的man窗口 我把'p.ProcessName!=在where表达式中使用“explorer”,因为explorer是桌面的主进程,永远不应该关闭它
要监视流程的执行,可以使用“ManagementEventWatcher”类。请看。我正试图给出答案,即使这篇文章已经发表一年多了 请尝试使用以下代码段:
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 */
}
这里需要注意的是获取进程p
的方法,即:
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
相关的更多信息,包括窗口/应用程序名称 我只想要java代码。。。。进程p=Runtime.getRuntime().exec(System.getenv(“windir”)+“\\system32\\”+“tasklist.exe”);这一个也得到了所有的过程,我需要单独的应用程序有什么办法得到它吗
var openWindowProcesses = System.Diagnostics.Process.GetProcesses()
.Where(p => p.MainWindowHandle != IntPtr.Zero && p.ProcessName != "explorer");
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 = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe /v /FI \"STATUS eq RUNNING\" /FI \"imagename eq javaw.exe\"");