Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
June 16, 2004
A. To reboot the local machine from a VBScript script, you can use the following code. For the code to work, Windows Management Instrumentation (WMI) must be installed on the machine you're rebooting.
Set OpSysSet =GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery_("select * from Win32_OperatingSystem where Primary=true")for each OpSys in OpSysSet OpSys.Reboot()next
(The GetObject line wraps to two lines here because of space constraints.) To shut down the machine, change the OpSys.Reboot() line to OpSys.Shutdown(). You can download the script here.
You May Also Like