PC Review Forums Newsgroups Windows XP Windows XP WMI Re: Reboot script

Reply

Re: Reboot script

 
Thread Tools Rate Thread
Old 05-08-2004, 10:14 PM   #1
David Holcomb
Guest
 
Posts: n/a
Default Re: Reboot script


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

"Mike Potter" <anonymous@discussions.microsoft.com> wrote in message
news:996001c433dc$2ee8ffe0$a601280a@phx.gbl...
>I hope that this is right group to ask. I have xp pro and
> I would like to have the computer automatically reboot at
> a user specified time. I'm not sure how to do this. I
> heard that I could download a pre-written script file to
> notepad and name it and run from task manager. Can
> someone tell me if this is true and if so what site or
> resourse I could go to for instructions.
> Thanks



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off