Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for processes.vbs

(view source code of processes.vbs as plain text)

  1. ' Processes.vbs,  Version 1.00
  2. ' Display all running processes.
  3. '
  4. ' Written by Rob van der Woude
  5. ' http://www.robvanderwoude.com
  6.  
  7.  
  8. ' Initialize error message variable
  9. strMsg = ""
  10.  
  11. ' Check command line parameters
  12. Select Case WScript.Arguments.Count
  13. 	Case 0
  14. 		' Default if none specified is local computer (".")
  15. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  16. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  17. 		For Each objItem in colItems
  18. 			strComputer = objItem.Name
  19. 		Next
  20. 	Case 1
  21. 		' Command line parameter can either be a computer name
  22. 		' or "/?" to request online help
  23. 		strComputer = Wscript.Arguments(0)
  24. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  25. 	Case Else
  26. 		' Maximum is 1 command line parameter
  27. 		Syntax
  28. End Select
  29.  
  30. On Error Resume Next
  31. ' Query and display running processes
  32. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  33. ' Display error number and description if applicable
  34. If Err.Number Then
  35. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  36. 	         Err.Description & vbCrLf & vbCrLf
  37. 	Syntax
  38. End If
  39. On Error GoTo 0
  40. Set colItems = objWMIService.ExecQuery( "Select * from Win32_Process", , 48 )
  41. For Each objItem in colItems
  42.     Wscript.Echo objItem.Caption & vbTab & objItem.ExecutablePath
  43. Next
  44.  
  45. ' Done
  46. WScript.Quit(0)
  47.  
  48.  
  49. Sub Syntax
  50. 	strMsg = strMsg & vbCrLf & "Processes.vbs,  Version 1.00" & vbCrLf & _
  51. 	         "Display all running processes." & vbCrLf & vbCrLf & _
  52. 	         "Usage:  CSCRIPT  PROCESSES.VBS  [ computer_name ]" & _
  53. 	         vbCrLf & vbCrLf & _
  54. 	         "Where:  " & Chr(34) & "computer_name" & Chr(34) & _
  55. 	         " is the name of a WMI enabled computer on the network" & _
  56. 	         vbCrLf & vbCrLf & _
  57. 	         "Written by Rob van der Woude" & vbCrLf & _
  58. 	         "http://www.robvanderwoude.com" & vbCrLf & vbCrLf & _
  59. 	         "Created using Microsoft's Scriptomatic tool" & vbCrLf & _
  60. 	         "http://www.microsoft.com/technet/treeview/default.asp?" & _
  61. 	         "url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  62. 	WScript.Echo strMsg
  63. 	' Abort with return code 1
  64. 	WScript.Quit(1)
  65. End Sub
  66.  

page last modified: 2024-04-16; loaded in 0.0067 seconds