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

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"