Q. How can I use a VBScript script to reboot or shut down my server?

John Savill

June 16, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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.

About the Author

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.

You May Also Like