我需要.vbs文件来检查特定进程是否处于活动状态,并且(如果是)终止它。
答案 0 :(得分:1)
与此线程相同?
How to terminate process using VBScript
除了您只需更改以下行:
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'")
到
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strMyProcess & "'")
答案 1 :(得分:1)
Set WShell=CreateObject("Wscript.shell)
WShell.Run "cmd.exe /c tasklist /fi ""imagename EQ excel*"" && taskkill /f /im excel.exe",0,False
如果成功在进程列表中找到excel.exe,它将杀死该进程
答案 2 :(得分:0)
myProcess="chrome.exe" 'repleace chrome.exe with your process name
Set Processes = GetObject("winmgmts:").InstancesOf("Win32_Process")
For Each Process In Processes
If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then 'check if process exist
Process.Terminate() 'kill the process you find
End If
Next