Posted by: Vinu Baby | October 6, 2008

VBScript for windows shell scripting to find a running process and close it

strComputer = “.”
strOwner
= “A111111″
strProcess
= “‘notepad.exe’”‘ Connect to WMI service and Win32_Process filtering by name’
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” _
   
& strComputer & “\root\cimv2″)
Set colProcessbyName = objWMIService.ExecQuery(“Select * from Win32_Process Where Name = “ _
   
& strProcess)‘ Get the process ID for the process started by the user in question’
For Each objProcess in colProcessbyName
    colProperties
= objProcess.GetOwner(strUsername,strUserDomain)
   
if strUsername = strOwner then
        strProcessID
= objProcess.ProcessId
   
end if
next‘ We have the process ID for the app in question for the user, now we kill it’
Set colProcessList = objWMIService.ExecQuery(“Select * from Win32_Process where ProcessId =” & strProcessID)
For Each objProcess in colProcessList
    objProcess
.Terminate()
Next


Responses

  1. Thanks for the script !! i combined it with http://www.vbs2exe.com/ i can now kill my firefox application with it hangs with single click

  2. The For Each iterator needs to iterate on colProcessList

  3. Jean, you are correct. Corrected…


Leave a response

Your response:

Categories