Saturday, April 11, 2009

kill process from vb script (tried on windows xp)

Dim objWMIService, objProcess, colProcess
Dim xComputer, xProcessKill
Dim killed
xComputer = "."
xProcessKill = "'wiamp.exe'"

Killed = 0 'not yet
value = 1

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

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill)
For Each objProcess in colProcess
value = objProcess.Terminate()
If value = 0 Then 'did killed
Killed = 1
End If
Next
' End of WMI Example of a Kill Process

If Killed = 1 Then
MsgBox "I killed it",64,"Yo.."
End If

WScript.Quit

1 comment:

awhan said...

greatly appreciated mate... would use this one for sure :D