首页 > 解决方案 > 如何在java中杀死任务管理器?

问题描述

在我的程序中,如果任务管理器正在运行,我想杀死它。我试过这个:

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

但任务管理器仍在运行。我能做些什么?

标签: javakill-process

解决方案


好吧,要杀死taskmanager,您需要管理员权限。对于这个下载这个

现在将任何一个文件 Elevate.exe 或 Elevate64.exe 复制到您的 java 项目源路径中。

然后

Runtime.getRuntime().exec("src//Elevate64.exe TASKKILL /F /IM Taskmgr.exe"); 

现在它将提示是或否。点击是.... 和 BOOM


推荐阅读