Tip 79: Logoff, Reboot, Power Off, or Shut Down a machine

Have you ever needed to remotely shut down, power off or reboot one or multiple machines?
Or just wanting to logoff the current user on one or even multiple machines, because you needed a logon script to be (re-)executed?

The Microsoft Windows 2000 resource kit provides a script called Restart.vbs that lets you easily achieve just that.

Note: To avoid accidental running of the script, the scripts on this web server are stored as *.vb_ file. Clicking on the link will bring up the script in the browser. From there you can save it for later use, simply by selecting All text in the browser window and copy/pasting it into your own newly created .vbs script file.

The syntax of this script allows for the following parameters:

Restart.vbs [/S <server>] [/U <username>] [/W <password>] [/O <outputfile>] </L> </R> </P> </Q> </F> [/T <time in seconds>]

The various parameters specify:
/T Amount of time to perform the function
/Q Perform Shutdown
/P Perform Poweroff
/R Perform Reboot
/L Perform Logoff
/F Force Function
NOTE: The force option will make the machine perform the function even if there are open and unsaved documents on the screen. Therefor this option might cause the loss of data or the corruption of files.
server A machine name
username The current user’s name
password Password of the current user
outputfile The output file name

Executing this script from within another script of possibly a batch-file provides an easy way of "automating" the task on multiple machines.
Some examples examples of execution of this script:

cscript Restart.vbs /S MyMachine2 /R
Reboots the machine named MyMachine2.

cscript Restart.vbs /S MyMachine2 /R /F
Forces the machine named MyMachine2 to reboot.

cscript Restart.vbs /S MyMachine2 /R /T 30
Reboots the machine named MyMachine2 in 30 seconds.

cscript Restart.vbs /s MyMachine /u john /w blowfish1 /L /T 2 /F
Will force a logoff of a user named john, with a password of "blowfish1" in 2 seconds.
Obviously here you need information that may not be available, like the current password.