Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

26May/100
Using VBScript to Kill a Process in Windows

After listing a process, you may want to kill or terminate a process:

strComputer = "."
strProcess = "'iexplore.exe'"

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

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcess )

For Each objProcess in colProcess
	objProcess.Terminate()
	WScript.Echo "Killed Process: " & objProcess.Name & vbTab & objProcess.ProcessId
Next
26May/100
Using VBScript to List Processes in Windows

Just like ps, this VBScript will return the running processes. Just like using Task Manager. Very simple.

strComputer = "."

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

For Each objProcessin objWMIService.InstancesOf("Win32_process")
   WScript.Echo objProcess.Name & vbTab & objProcess.ProcessId
Next

WScript.Echo "End of Process List"

Another method:

strComputer = "."

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

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

For Each objProcess in colProcess
	WScript.Echo objProcess.Name & vbTab & objProcess.ProcessId
Next

WScript.Echo "End of Process List"
13Apr/100
Display Process List Using VBScript

This great VBScript script will display running processes on a Windows workstation. The script queries the Win32_Process from a WMI Object using ExecQuery then loops through the results. To access the process list on another server, set the strComputer variable to the server's name.

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

strComputer = "."

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

Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcess
	strList = strList & vbCr & objProcess.Name
Next

WSCript.Echo strList
WScript.Quit