我已经多次使用下面的脚本来杀死vbscript中的进程而没有任何问题。
这次我试图杀死explorer.exe。唯一的问题是在我使用脚本在2秒内浏览器进程恢复后杀死explorer.exe。
我不明白?因为如果我用任务管理器手动杀死explorer.exe,该进程将被终止,直到我再次启动该进程。那么下面的脚本问题是什么?Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'explorer.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WScript.Quit
答案 0 :(得分:1)
您可以尝试这样:
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'explorer.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate(1)
Next
或者这样:
Option Explicit
Dim Process
Process = "Explorer.exe"
Call Kill(Process)
'****************************************************
Sub Kill(Process)
Dim Ws,Command,Execution
Set Ws = CreateObject("Wscript.Shell")
Command = "cmd /c Taskkill /F /IM "& Process &""
Execution = Ws.Run(Command,0,True)
Set Ws = Nothing
End Sub
'****************************************************
答案 1 :(得分:1)
一种方式:
Set oCMD = CreateObject("WScript.Shell")
oCMD.Run "taskkill /f /im explorer.exe",0,True