1

I need a .vbs file to check if a specific process is active and (if it is) terminate it.

Eta Beta
  • 157
  • 1
  • 3
  • 11
  • I saw that one but I need **to check if a specific process is active** ... and (if it is) terminate it... In that particular example I could not see the part related to checking the existence of a specific active process. – Eta Beta Oct 20 '12 at 07:36

2 Answers2

0

Same as this thread?

How to terminate process using VBScript

Except that you just change the following line:

Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'")

to

Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strMyProcess  & "'")
Community
  • 1
  • 1
SolidRegardless
  • 427
  • 3
  • 17
  • I did replace that line as you suggested but I must have done something wrong. Could you please tell me if/how the section **& strMyProcess &** needs to be edited assuming I want to kill a process called "KM Player.exe" – Eta Beta Oct 20 '12 at 17:45
  • Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'KMPlayer.exe'") – SolidRegardless Oct 21 '12 at 13:58
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
hollopost
  • 569
  • 9
  • 28