(view source code of shutdown.vbs as plain text)
Option Explicit
Dim strComputer, strQuery
' Check command line arguments
If WScript.Arguments.Named.Count > 0 Then Syntax
Select Case WScript.Arguments.Unnamed.Count
Case 0
' Default is local computer if none specified
strComputer = "."
Case 1
If InStr( WScript.Arguments.Unnamed(0), "?" ) > 0 Then
' A "?" in the argument means display help
Syntax
Else
strComputer = WScript.Arguments.Unnamed(0)
End If
Case Else
' No more than 1 argument allowed
Syntax
End Select
' Connect to computer
strQuery = "SELECT * FROM Win32_OperatingSystem WHERE Primary=True"
Set OpSysSet = GetObject( "winmgmts:{(Shutdown)}//" & strComputer & "/root/cimv2" ).ExecQuery( strQuery )
' Actual shutdown command
For Each OpSys In OpSysSet
OpSys.Shutdown()
Next
Sub Syntax
Dim strMsg
strMsg = "Shutdown.vbs, Version 1.10" & vbCrLf _
& "Shutdown any WMI enabled computer on the network." _
& vbCrLf & vbCrLf _
& "Usage: " & UCase( WScript.ScriptName ) _
& " [ computer_name ]" & vbCrLf & vbCrLf _
& "Where: ""computer_name"" is the name of the " _
& "computer to be shut down (no" & vbCrLf _
& " leading backslashes); " _
& "default is the local computer." & vbCrLf & vbCrLf _
& "Based on a post by Alex Angelopoulos on www.developersdex.com." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
Wscript.Echo( strMsg )
Wscript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0057 seconds