Re: Reboot script

D

David Holcomb

Save this to a file called shutdown.vbs then run "cscript shutdown.vbs force
reboot" to reboot the computer. If you want to give apps a chance to save
opened files, don't add the force option..

'***************************************************************************
'
' WMI Script - System shutdown (VBScript)
'
' Invokes the Win32Shutdown method of the Win32_OperatingSystem class.
' Supports logoff, reboot, shutdown/poweroff, and forcing the system to
ignore
' any dialogs that pop up.
'
' NOTE: You must have the Shutdown privilege to successfully invoke the
Shutdown method
'
'***************************************************************************
Dim ArgObj
Dim OpSysSet
Dim OpSys
Dim ShutdownFlags
Dim Reserved
Dim i

'
' Basic flags for Win32_OperatingSystem.Win32Shutdown()
'
const WMI_LOGOFF = &H0
const WMI_SHUTDOWN = &H1
const WMI_REBOOT = &H2
const WMI_POWEROFF = &H8

'
' This flag can be added to any of the above to force the action (ignoring
dialogs/prompts)
'
const WMI_FORCE = &H4

const LOGOFF = "logoff"
const SHUTDOWN = "shutdown"
const REBOOT = "reboot"
const POWEROFF = "poweroff"
const FORCE = "force"

set OpSysSet =
GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from
Win32_OperatingSystem where Primary=true")

ShutdownFlags = 0
Reserved = 0

' Get the Arguments object
set ArgObj = WScript.Arguments

if ArgObj.Count = 0 then
WScript.Echo "Usage: cscript shutdown.vbs [[force]
logoff|shutdown|reboot|poweroff]"
WScript.Quit 0
end if

for i = 0 to ArgObj.Count - 1

if (StrComp(ArgObj.Item(i), LOGOFF, vbTextCompare) = 0) then
ShutdownFlags = ShutdownFlags Or WMI_LOGOFF
WScript.Echo "Logoff"
elseif (StrComp(ArgObj.Item(i), SHUTDOWN, vbTextCompare) = 0) then
ShutdownFlags = ShutdownFlags Or WMI_SHUTDOWN
WScript.Echo "Shutdown"
elseif (StrComp(ArgObj.Item(i), REBOOT, vbTextCompare) = 0) then
ShutdownFlags = ShutdownFlags Or WMI_REBOOT
WScript.Echo "Reboot"
elseif (StrComp(ArgObj.Item(i), POWEROFF, vbTextCompare) = 0) then
ShutdownFlags = ShutdownFlags Or WMI_POWEROFF
WScript.Echo "Power Off"
elseif (StrComp(ArgObj.Item(i), FORCE, vbTextCompare) = 0) then
ShutdownFlags = ShutdownFlags Or WMI_FORCE
WScript.Echo "Force"
else
WScript.Echo "Invalid parameter '" & ArgObj.Item(i) & "' specified"
end if

next

for each OpSys in OpSysSet
call OpSys.Win32Shutdown(ShutdownFlags, Reserved)
next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top