以下は、ウィンドウからプロセスのリストを取得するために使用されます
Process proc = Runtime.getRuntime().exec ("tasklist.exe");
しかし、アプリケーションタブのコンテンツ自体を取得したいのですが、これには解決策が必要です
Process proc = Runtime.getRuntime().exec ( ? ? ?);
投稿がすでに1年以上経過していても、答えようとしています。
次のコード スニペットを試してください。
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
。つまり、次のようになります。
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe /v /FI \"STATUS eq RUNNING\" /FI \"imagename eq javaw.exe\"");
/FI "STATUS eq RUNNING" /FI "imagename eq javaw.exe"
呼び出し時に追加されたフィルターにより、ウィンドウ/アプリケーション名など、tasklist.exe
プロセスに関連する詳細情報を取得できます。javaw.exe