How to close all the open application on windows using java? -


i have made package of exe installer of following code close open application on windows platform. exe working fine on machine on written i.e. windows 8.1 pro (32 bit os / x64 based processor) same exe not working on windows 7 or different machine.

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();         } 

on windows 8 working fine, on windows 7 showing exceptions follows: (output + exception)

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     @ java.lang.string.substring(string.java:1955)     @ decryptomediaplayer.decryptomediaplayer.main(decryptomediaplayer.java:731)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ com.sun.javafx.application.launcherimpl.launchapplicationwithargs(launcherimpl.java:389)     @ com.sun.javafx.application.launcherimpl.launchapplication(launcherimpl.java:328)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ sun.launcher.launcherhelper$fxhelper.main(launcherhelper.java:767) java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ com.sun.javafx.application.launcherimpl.launchapplicationwithargs(launcherimpl.java:389)     @ com.sun.javafx.application.launcherimpl.launchapplication(launcherimpl.java:328)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ sun.launcher.launcherhelper$fxhelper.main(launcherhelper.java:767) caused by: java.lang.illegalstateexception: not on fx application thread; currentthread = main     @ com.sun.javafx.tk.toolkit.checkfxuserthread(toolkit.java:204)     @ com.sun.javafx.tk.quantum.quantumtoolkit.checkfxuserthread(quantumtoolkit.java:438)     @ javafx.stage.stage.<init>(stage.java:238)     @ javafx.stage.stage.<init>(stage.java:224)     @ javafx.scene.control.heavyweightdialog$1.<init>(heavyweightdialog.java:50)     @ javafx.scene.control.heavyweightdialog.<init>(heavyweightdialog.java:50)     @ javafx.scene.control.dialog.<init>(dialog.java:262)     @ javafx.scene.control.alert.<init>(alert.java:245)     @ javafx.scene.control.alert.<init>(alert.java:223)     @ decryptomediaplayer.decryptomediaplayer.main(decryptomediaplayer.java:750)     ... 11 more exception running application decryptomediaplayer.decryptomediaplayer java result: 1 

the reason simple. code cannot handle processes in uppercase letters.

string line = "pwrisovm.exe   2152 console"; string pocesskill = line.substring(0, line.indexof(".exe")); 

this lead into

java.lang.stringindexoutofboundsexception: string index out of range: -1 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -