在我的程序中,如果任务管理器正在运行,我想杀死它。我试过这个:
private static final String TASKLIST = "tasklist";
private static final String KILL = "taskkill /F /IM ";
if(isProcessRunning("Taskmgr.exe")){
// TODO code application logic here
killProcess("Taskmgr.exe");
}
这是我的isProcessRunning()方法:
public static boolean isProcessRunning(String servicename) throws Exception {
Process p = Runtime.getRuntime().exec(TASKLIST);
BufferedReader reader = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
if (line.contains(servicename)) {
System.err.println(line);
return true;
}
}
return false;
}
和killprocess()方法:
public static void killProcess(String serviceName) throws Exception {
Runtime.getRuntime().exec(KILL + serviceName);
}
但任务管理器仍在运行。我能做什么?
catspeake
有只小跳蛙
呼唤远方
相关分类