gpt4 book ai didi

java - 当发送命令的程序不是管理员时,如何强制关闭以管理员身份运行的进程?

转载 作者:行者123 更新时间:2023-12-02 03:21:23 25 4
gpt4 key购买 nike

出于测试和安全目的,我正在尝试制作一个强制关闭某些进程的Java程序。我正在使用“taskmgr.exe”进程和“cmd.exe”进程对其进行测试。

无论如何,它可以与taskmgr.exe一起正常工作,但如果命令提示符不以管理员身份运行,它只能在cmd.exe上工作。我正在使用 taskkill/F 在我的代码中关闭这些:

String line;
String pidInfo = "";
while (true) {
Process p = null;
try {
p = Runtime.getRuntime().exec(
System.getenv("windir") + "\\system32\\"
+ "tasklist.exe");
} catch (IOException e1) {
e1.printStackTrace();
}
BufferedReader input = new BufferedReader(new InputStreamReader(
p.getInputStream()));
try {
while ((line = input.readLine()) != null) {
pidInfo += line;
}
} catch (IOException e1) {
e1.printStackTrace();
}

try {
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}

if (pidInfo.contains("taskmgr.exe")) {
Runtime rt = Runtime.getRuntime();
try {
rt.exec("taskkill /F /T /IM taskmgr.exe");
} catch (IOException e) {
e.printStackTrace();
}
}
if(pidInfo.contains("cmd.exe")) {
Runtime rt = Runtime.getRuntime();
try {
rt.exec("taskkill /F /T /IM cmd.exe");
} catch(IOException ex) {
ex.printStackTrace();
}
}
}

这一切都运行得很好。但是我该如何修改代码才能强制管理命令提示符退出呢?出于我的目的,我无法以管理员身份运行 Java 程序。这可能吗?

最佳答案

长话短说,您是在问非管理进程是否可以杀死管理进程。

这是不可能的。

因此,无论对代码进行多少更改都无法实现这一目标。

(至少没有一些 m4d h4x0r ski11z,我们不允许在这里讨论。)

关于java - 当发送命令的程序不是管理员时,如何强制关闭以管理员身份运行的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39561360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com