windows 如何使用 VBScript 终止进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/893237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to terminate process using VBScript
提问by Jose Basilio
I have this VBScript code to terminate one process
我有这个 VBScript 代码来终止一个进程
Const strComputer = "."
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
It works fine with some processes, but when it comes to any process runs under SYSTEM, it can't stop it.
它对某些进程运行良好,但是当涉及在 SYSTEM 下运行的任何进程时,它无法阻止它。
Is there is anything I need to add to kill the process under SYSTEM?
是否需要添加任何内容来终止 SYSTEM 下的进程?
回答by Jose Basilio
The way I have gotten this to work in the past is by using PsKillfrom Microsoft's SysInternals. PsKill can terminate system processes and any processes that are locked.
我过去使用它的方法是使用Microsoft 的SysInternals 中的 PsKill。PsKill 可以终止系统进程和任何被锁定的进程。
You need to download the executable and place it in the same directory as the script or add it's path in the WshShell.Exec call. Here's your sample code changed to use PsKill.
您需要下载可执行文件并将其放置在与脚本相同的目录中,或者将其路径添加到 WshShell.Exec 调用中。这是您更改为使用 PsKill 的示例代码。
Const strComputer = "."
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'")
For Each objProcess in colProcessList
WshShell.Exec "PSKill " & objProcess.ProcessId
Next
回答by omegastripes
Try explicit assert debug privilege {impersonationLevel=impersonate,(debug)}
:
尝试显式断言调试权限{impersonationLevel=impersonate,(debug)}
:
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate,(debug)}!\.\root\CIMV2")
Set procs = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='SearchIndexer.exe'", , 48)
For Each proc In procs
proc.Terminate
Next