Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for reboot.vbs

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

  1. Option Explicit
  2.  
  3. Dim strComputer, strQuery
  4.  
  5. ' Check command line arguments
  6. If WScript.Arguments.Named.Count > 0 Then Syntax
  7. Select Case WScript.Arguments.Unnamed.Count
  8. 	Case 0
  9. 		' Default is local computer if none specified
  10. 		strComputer = "."
  11. 	Case 1
  12. 		If InStr( WScript.Arguments.Unnamed(0), "?" ) > 0 Then
  13. 			' A "?" in the argument means display help
  14. 			Syntax
  15. 		Else
  16. 			strComputer = WScript.Arguments.Unnamed(0)
  17. 		End If
  18. 	Case Else
  19. 		' No more than 1 argument allowed
  20. 		Syntax
  21. End Select
  22.  
  23. ' Connect to computer
  24. strQuery     = "SELECT * FROM Win32_OperatingSystem WHERE Primary=True"
  25. Set OpSysSet = GetObject( "winmgmts:{(Shutdown)}//" & strComputer & "/root/cimv2" ).ExecQuery( strQuery )
  26.  
  27. ' Actual reboot command
  28. For Each OpSys In OpSysSet
  29. 	OpSys.Reboot()
  30. Next
  31.  
  32.  
  33. Sub Syntax
  34. 	Dim strMsg
  35. 	strMsg = "Reboot.vbs,  Version 2.10" & vbCrLf _
  36. 	       & "Reboot any WMI enabled computer on the network." _
  37. 	       & vbCrLf & vbCrLf _
  38. 	       & "Usage:  " & UCase( WScript.ScriptName ) _
  39. 	       & "  [ computer_name ]" & vbCrLf & vbCrLf _
  40. 	       & "Where:  ""computer_name"" is the name of the " _
  41. 	       & "computer to be rebooted" & vbCrLf _
  42. 	       & "                        (without leading backslashes)." _
  43. 	       & vbCrLf & vbCrLf _
  44. 	       & "        Default is ""."" (the local computer)." _
  45. 	       & vbCrLf & vbCrLf _
  46. 	       & "Based on a post by Alex Angelopoulos on www.developersdex.com." _
  47. 	       & vbCrLf & vbCrLf _
  48. 	       & "Written by Rob van der Woude" & vbCrLf _
  49. 	       & "http://www.robvanderwoude.com"
  50. 	Wscript.Echo( strMsg )
  51. 	Wscript.Quit 1
  52. End Sub
  53.  

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