Pages

Monday, 29 August 2011

VBScript to Terminate Process

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strProcessKill = "'ProcessName.exe'" 
Set objWMIService = GetObject("winmgmts:root\cimv2") 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next 
WScript.Quit

3 comments:

  1. thanks ... I need to kill multiple processes with a single script.
    is it possible?

    ReplyDelete
  2. Yes you can do it. run the code multiple timnes within a single script

    ReplyDelete
  3. Hello,
    I'm sorry I didn't understand ... you give an example ..
    that is, for example, I just add the following lines in the script?

    Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill
    strProcessKill = "'WinRAR.exe'"
    strProcessKill = "'notepad.exe'"
    strProcessKill = "'IEXPLORE.exe'"
    Set objWMIService = GetObject("winmgmts:root\cimv2")
    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
    objProcess.Terminate()
    Next
    WScript.Quit

    thanks again....

    ReplyDelete