Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for servicestd.vbs

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

  1. ' ServicesTD.vbs,  Version 1.00
  2. ' Display all services installed in a TAB delimited format.
  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. ' Set header for screen output
  40. strMsg = "Name:" & vbTab _
  41.        & "DisplayName:" & vbTab _
  42.        & "PathName:" & vbTab _
  43.        & "StartMode:" & vbTab _
  44.        & "State:" & vbTab _
  45.        & "StartName:" & vbCrLf
  46.  
  47. ' List all services and their properties
  48. For Each objItem in colItems
  49. 	strMsg = strMsg _
  50. 	       & objItem.Name & vbTab _
  51. 	       & objItem.DisplayName & vbTab _
  52. 	       & objItem.PathName & vbTab _
  53. 	       & objItem.StartMode & vbTab _
  54. 	       & objItem.State & vbTab _
  55. 	       & objItem.StartName & vbCrLf
  56. Next
  57.  
  58. ' Display the results
  59. Wscript.Echo strMsg
  60.  
  61. ' Done
  62. WScript.Quit(0)
  63.  
  64.  
  65. Sub Syntax
  66. msg = vbCrLf & "ServicesTD.vbs,  Version 1.00" & vbCrLf _
  67.     & "Display all services for any WMI enabled computer on the network" _
  68.     & vbCrLf & "in a TAB delimited format." _
  69.     & vbCrLf & vbCrLf _
  70.     & "Usage:  CSCRIPT  SERVICESTD.VBS  [ computer_name ]" _
  71.     & vbCrLf & vbCrLf _
  72.     & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  73.     & " is the name of the computer to whose services" & vbCrLf _
  74.     & "        are to be displayed (without leading backslashes)." _
  75.     & vbCrLf & vbCrLf _
  76.     & "        Default is " & Chr(34) & "." & Chr(34) _
  77.     & " (the local computer)." _
  78.     & vbCrLf & vbCrLf _
  79.     & "Written by Rob van der Woude" & vbCrLf _
  80.     & "http://www.robvanderwoude.com" _
  81.     & vbCrLf & vbCrLf _
  82.     & "Created using Microsoft's Scriptomatic tool" & vbCrLf _
  83.     & "http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/WMImatic.asp"
  84. Wscript.Echo(msg)
  85. Wscript.Quit(1)
  86. End Sub
  87.  

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