All about the Shutdown Command


The ability to restart and shutdown computers automatically or remotely is key to completing installs, fixing issues, or just having a hell of a time messing with end users. In this post ill detail all the switches and uses of the shutdown command.

For anyone that is not familiar with the command ‘shutdown’, it is a windows/dos function that controlls the the shutdown, logoff and restart of a compiter or server either locally or remotely.

Here are the switches 

shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]


Just typing shutdown won’t do anything;  you need arguments. 

  • -i   This will display the GUI interface for the shutdown command.  This works well in some cases though you do get more flexability with the command line options.
  • -l  This will log off the current session on the computer.  This cannot be used on remote computers though. 
  • -s This will turn off the computer, this can be done remotely, but carefull you can’t remotely press the power botton on the front of the box!
  • -r  This will restart the local or remote computer.  Usefull stuff.
  • -a  This will cancel the shutdown restart or logoff process, this must be used before the shutdown commences (during the countdown).
  • -m  This is what allows you to specify the name of the computer you want to perform the action on (shutdown, restart or abort).
  • -t  This lets you chose how long you want to display the warning message for in seconds.  You can use ‘-t 0′ to immediatly start the shutdown process with no message displayed.
  • -c  This lets you specify the reason that you shutdown or restarted in the event log.  There is a max of 127 chracters for this switch.
  • -f  This forces all applications to close with no warning.  This should almost always be used with a remote computer so you dont have a box asking if you would like to shave chnages to ‘untitled.txt’ on the screen instead of it actually rebooting.
  • -d  This switch will let you specify the reason for the shutdown using microsoft reason codes. ‘u’ is for user code ‘p’ is for planned and the ‘xx’ is to specify a major reason, while ‘yy’ is to specify a minor reason.

So putting it all together.

shutdown -r -f -m\\remotecomputer -t 60 -c “reboot required to complete software install”

This will restart the the computer ‘remotecomputer’  after 60 seconds of displaying the message “reboot required to complete software install”.  To abort the shutdown within 60 seconds, issue the following command.

shutdown -a -m \\remotecomputer

If the remote shutdown is not working for you remember that if you are in a workgroup the account you are logged in with must exist on, and have administrative rights on the remote computer. If you are on a domain, the user account must have SeRemoteShutdownPrivilege and SeShutdownPrivilege to accomplish this. 

Here are some other interesting notes on this function/script:  It can be batched and run as a scheduled task.  For example, saving the above script as a restart.bat and scheduling it to run at a specified time will give you the ability to reboot a server at whatever time you want. Additionally, shutdown commands can be used via telnet.  You can telnet to a remote computer or server and issue the shutdown command to reboot the target computer.  Lets face it, sometimes you have to install something with administrative rights, but you don’t want to wait for it to finish. So just batch it and add a logoff command right after the install.  I use this all the time when I install office.  I login to a computer with an elevated account, and run a batch file to install office silently with a shutdown -l -t 0 at the end of the batch file, then lock the computer.  The install will finish and the account will logoff, its a useful little trick. Lastly with Kaseya; since this is directly a shell command you can issue it with just a few steps. 
 

Script Name: Shutdown    

Script Description: Shutdown the computer using Shutdown.exe

IF True 

THEN

   Execute Shell Command

     Parameter 1 : shutdown -s -f -t 1 -c “Setup complete”

     Parameter 2 : 0

         OS Type : 0

ELSE

Change the red to match your needs and away you go.

,

  1. #1 by brian on April 12, 2009 - 4:13 pm

    thanks very much. This is quite useful!

(will not be published)