私はWindowsプラットフォーム上のすべての開いているアプリケーションを閉じるために、次のコードのexeインストーラのパッケージを作っています。 exeが書かれているマシン、つまりWindows 8.1 Pro(32ビットOS/X64ベースプロセッサ) でも問題なく動作していますが、Windows 7または別のマシンでは同じexeファイルが動作していません。 Windows 8のその細かい作業が、上のWindows 7の上映の例外は次のようにJavaを使用しているウィンドウで開いているアプリケーションをすべて終了するにはどうすればいいですか?
try {
String line;
Process p = Runtime.getRuntime().exec("tasklist.exe");
Runtime rt = Runtime.getRuntime();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (line.toLowerCase().contains(".exe".toLowerCase()) && line.toLowerCase().contains("Console".toLowerCase())) {
System.out.println(line);
String pocessKill = line.substring(0, line.indexOf(".exe"));
pocessKill = pocessKill + ".exe";
if (pocessKill.equalsIgnoreCase("netbeans.exe") || pocessKill.equalsIgnoreCase("java.exe") || pocessKill.equalsIgnoreCase("csrss.exe") || pocessKill.equalsIgnoreCase("winlogon.exe") || pocessKill.equalsIgnoreCase("dwm.exe") || pocessKill.equalsIgnoreCase("taskhostex.exe") || pocessKill.equalsIgnoreCase("explorer.exe") || pocessKill.equalsIgnoreCase("igfxtray.exe") || pocessKill.equalsIgnoreCase("hkcmd.exe") || pocessKill.equalsIgnoreCase("igfxpers.exe") || pocessKill.equalsIgnoreCase("jusched.exe") || pocessKill.equalsIgnoreCase("GWX.exe") || pocessKill.equalsIgnoreCase("rundll32.exe") || pocessKill.equalsIgnoreCase("conhost.exe") || pocessKill.equalsIgnoreCase("tasklist.exe") || pocessKill.equalsIgnoreCase("conhost.exe")) {
System.out.println(pocessKill);
} else {
rt.exec("taskkill /F /IM " + pocessKill);
}
} else {
System.out.println("Bad Process");
}
}
input.close();
System.out.println(rt.toString());
} catch (Exception err) {
err.printStackTrace();
}
: (出力+例外)
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
csrss.exe 936 Console 1 22,612 K
csrss.exe
Bad Process
winlogon.exe 1016 Console 1 3,508 K
winlogon.exe
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
dwm.exe 1928 Console 1 33,116 K
dwm.exe
explorer.exe 1944 Console 1 60,328 K
explorer.exe
Bad Process
Bad Process
Bad Process
Bad Process
Bad Process
PWRISOVM.EXE 2152 Console 1 3,456 K
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1955)
at decryptomediaplayer.DecryptoMediaPlayer.main(DecryptoMediaPlayer.java:731)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.IllegalStateException: Not on FX application thread; currentThread = main
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:438)
at javafx.stage.Stage.<init>(Stage.java:238)
at javafx.stage.Stage.<init>(Stage.java:224)
at javafx.scene.control.HeavyweightDialog$1.<init>(HeavyweightDialog.java:50)
at javafx.scene.control.HeavyweightDialog.<init>(HeavyweightDialog.java:50)
at javafx.scene.control.Dialog.<init>(Dialog.java:262)
at javafx.scene.control.Alert.<init>(Alert.java:245)
at javafx.scene.control.Alert.<init>(Alert.java:223)
at decryptomediaplayer.DecryptoMediaPlayer.main(DecryptoMediaPlayer.java:750)
... 11 more
Exception running application decryptomediaplayer.DecryptoMediaPlayer
Java Result: 1
「動作していません」とはどういう意味ですか?エラーメッセージはありますか?あなたの望む結果は何ですか? 'tasklist |によって返されたすべての' Console'プロセスを強制終了するにはfindstrコンソール|あなたの除外リストを除くfindstr ".exe" – SubOptimal
@SubOptimal:Javaアプリケーションから実行中のアプリケーションをすべて閉じたいだけです。 –
その後、他の質問にも答えます。 「働いていない」とどういう意味ですか?エラーメッセージはありますか? – SubOptimal