我有这个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
它适用于某些进程,但是当涉及到在SYSTEM下运行的任何进程时,它无法阻止它。
我是否需要添加任何内容来杀死SYSTEM下的进程?
答案 0 :(得分:18)
我过去使用此功能的方法是使用Microsoft的SysInternals中的 PsKill 。 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
答案 1 :(得分:1)
尝试使用显式的断言调试特权{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