PDA

View Full Version : Kill Process using wsh?



pculmo
03-04-2004, 08:32 PM
Is there any to create a script that will kill win32 processes? I'm not asking for anyone to write it for me, just a link to see how it's done would suffice. This is so we can convert our batch files using the reskit kill to using WSH. Thanks!!!

Belaflek
03-11-2004, 07:06 AM
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

pculmo
03-11-2004, 05:32 PM
That works but what about Services that run in the LocalSystem Context? is there a way to kill processes like these instead of using the Kill util from the resource kit? My goal is to migrate from batch files to wsh scripts. Unless there's a way to call the Kill command from wsh (I have not figured out how yet) .

Thank you!