Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for services.vbs

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

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

page last uploaded: 2017-08-21, 14:26