Submitted By: Edgar Somosierra

Displays the processes running on a computer. The script accepts a computer name as an argument and displays help if an incorrect argument is used.

Visual Basic
Edit|Remove
If (Wscript.Arguments.named.exists("c")) And (Wscript.Arguments.named.Item("c") <> "") Then
	strComputer = WScript.arguments.named.item("c")
	
	On Error Resume Next
	
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select Name,Username from Win32_ComputerSystem",,48)
	For Each objItem in colItems
		Wscript.Echo "Name: " & objItem.Name
		Wscript.Echo "UserName: " & objItem.UserName
	Next
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	If Err > 0 Then
		Wscript.echo ""
		Wscript.echo "Error: " & err.description
		Wscript.quit
	End If	
	Wscript.echo "Processes:"
	Set colItems = objWMIService.ExecQuery("Select Name,ExecutablePath,ProcessID from Win32_Process",,48)
	For Each objItem In colItems
		Wscript.Echo vbTab & "Name: " & Ucase(objItem.Name)	
		Wscript.Echo vbTab & "ExecutablePath: " & objItem.ExecutablePath
		Wscript.Echo vbTab & "ProcessId: " & objItem.ProcessId
		Wscript.Echo ""
	Next

Else
	Wscript.echo ""
	Wscript.echo "Usage: cscript chkProcess.vbs /c:[computer_name]"
End If