当发送命令的程序不是管理员时,如何以管理员身份强制关闭进程 运行?
How do I force close a process run as admin, when program sending command is not admin?
出于测试和安全目的,我正在尝试制作一个 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 程序来强制关闭某些进程。我正在使用 "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,我们不能在这里谈论。)