检查特定进程是否处于活动状态并将其终止

时间:2012-10-20 07:12:50

标签: vbscript

我需要.vbs文件来检查特定进程是否处于活动状态,并且(如果是)终止它。

3 个答案:

答案 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