' Use our own error handling On Error Resume Next ' Initialize variable strMsg = "" ' Check command line parameters Select Case WScript.Arguments.Count Case 0 ' Default if none specified is local computer (".") Set objWMIService = GetObject( "winmgmts://./root/cimv2" ) ' Display error number and description if applicable If Err Then ShowErr Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 ) ' Display error number and description if applicable If Err Then ShowErr For Each objItem in colItems strComputer = objItem.Name Next Case 1 ' Command line parameter can either be a computer name ' or "/?" to request online help strComputer = Wscript.Arguments(0) if InStr( strComputer, "?" ) > 0 Then Syntax Case Else ' Maximum is 1 command line parameter Syntax End Select ' Link to the computer Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" ) ' Display error number and description if applicable If Err Then ShowErr ' Collect information on startup commands Set colItems = objWMIService.ExecQuery( "Select * from Win32_StartupCommand", , 48 ) ' Display error number and description if applicable If Err Then ShowErr ' Select and format data for display For Each objItem in colItems strMsg = strMsg & vbCrLf _ & "Name : " & objItem.Name & vbCrLf _ & "Command : " & objItem.Command & vbCrLf _ & "Location : " & objItem.Location & vbCrLf _ & "User : " & objItem.User & vbCrLf Next ' Display the result WScript.Echo strMsg 'Done WScript.Quit(0) Sub ShowErr() strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf _ & Err.Description & vbCrLf & vbCrLf Syntax End Sub Sub Syntax() strMsg = strMsg & vbCrLf _ & "Startup.vbs, Version 1.00" & vbCrLf _ & "Display startup commands and their locations for " _ & "any computer on the network" & vbCrLf & vbCrLf _ & "Usage: CSCRIPT STARTUP.VBS " _ & "[ computer_name ]" & vbCrLf & vbCrLf _ & "Where: " & Chr(34) & "computer_name" & Chr(34) _ & " is the optional name of a remote" & vbCrLf _ & " computer (default is local computer " _ & "name)" & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" & vbCrLf _ & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _ & "Created with Microsoft's Scriptomatic tool" & vbCrLf _ & "http://www.microsoft.com/technet/treeview/default.asp" _ & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf WScript.Echo strMsg WScript.Quit(1) End Sub