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

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish