Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for startup.vbs

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

  1. ' Use our own error handling
  2. On Error Resume Next
  3.  
  4. ' Initialize variable
  5. strMsg = ""
  6.  
  7. ' Check command line parameters
  8. Select Case WScript.Arguments.Count
  9. 	Case 0
  10. 		' Default if none specified is local computer (".")
  11. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  12. 		' Display error number and description if applicable
  13. 		If Err Then ShowErr
  14. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  15. 		' Display error number and description if applicable
  16. 		If Err Then ShowErr
  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. ' Link to the computer
  31. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  32. ' Display error number and description if applicable
  33. If Err Then ShowErr
  34.  
  35. ' Collect information on startup commands
  36. Set colItems = objWMIService.ExecQuery( "Select * from Win32_StartupCommand", , 48 )
  37. ' Display error number and description if applicable
  38. If Err Then ShowErr
  39.  
  40. ' Select and format data for display
  41. For Each objItem in colItems
  42. 	strMsg = strMsg & vbCrLf _
  43. 	       & "Name     : " & objItem.Name & vbCrLf _
  44. 	       & "Command  : " & objItem.Command & vbCrLf _
  45. 	       & "Location : " & objItem.Location & vbCrLf _
  46. 	       & "User     : " & objItem.User & vbCrLf
  47. Next
  48.  
  49. ' Display the result
  50. WScript.Echo strMsg
  51.  
  52. 'Done
  53. WScript.Quit(0)
  54.  
  55.  
  56. Sub ShowErr()
  57. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf _
  58. 	       & Err.Description & vbCrLf & vbCrLf
  59. 	Syntax
  60. End Sub
  61.  
  62.  
  63. Sub Syntax()
  64. 	strMsg = strMsg & vbCrLf _
  65. 	       & "Startup.vbs,  Version 1.00" & vbCrLf _
  66. 	       & "Display startup commands and their locations for " _
  67. 	       & "any computer on the network" & vbCrLf & vbCrLf _
  68. 	       & "Usage:  CSCRIPT  STARTUP.VBS  " _
  69. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  70. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  71. 	       & " is the optional name of a remote" & vbCrLf _
  72. 	       & "        computer (default is local computer " _
  73. 	       & "name)" & vbCrLf & vbCrLf _
  74. 	       & "Written by Rob van der Woude" & vbCrLf _
  75. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  76. 	       & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
  77. 	       & "http://www.microsoft.com/technet/treeview/default.asp" _
  78. 	       & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  79. 	WScript.Echo strMsg
  80. 	WScript.Quit(1)
  81. End Sub
  82.  

page last uploaded: 2017-04-06, 13:33