java - 如何在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);
}
但任务管理器仍在运行。我能做些什么?
解决方案
好吧,要杀死taskmanager,您需要管理员权限。对于这个下载这个。
现在将任何一个文件 Elevate.exe 或 Elevate64.exe 复制到您的 java 项目源路径中。
然后
Runtime.getRuntime().exec("src//Elevate64.exe TASKKILL /F /IM Taskmgr.exe");
现在它将提示是或否。点击是.... 和 BOOM
推荐阅读
- html - 节点静态 Web 服务器页面中的奇怪标题(“b8”)
- selenium-chromedriver - 使用 selenium 将 URL 自定义 URL 传递给 chrome 驱动程序时出现“参数无效异常错误”
- python - 如何提高在 python 中发送请求的速度?`
- asp.net - 使用 LinQ to SQL 搜索栏
- c - 用 base 实现 atoi() 函数
- python - 如何使用 asyncio 在异步生成器上进行“轮询”或“选择”
- javascript - 如何在数组中添加和替换对象的元素
- hellosign-api - HelloSign:如何通过 API 复制模板?
- protractor - 如何运行 Protractor 文件夹中的所有测试而不将其作为套件添加到配置文件中
- python - 如何在 PySpark 中创建空 Spark DataFrame 并附加数据?