Tuesday, November 15, 2005

WMI: Killing processes

Need to kill a process using WMI? Maybe outlook.exe isn't shutting down properly... maybe it hangs in taskmanager... maybe you're tired of fighting it on your workstation, and don't have a few spare hours RIGHT NOW to re-image your system. If any of the above apply, check out the below script.


Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill

strComputer = "."
strProcessKill = "'outlook.exe'"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next

WSCript.Echo "Outlook cleanup process complete, please reopen Outlook."
WScript.Quit

No comments: