#0252 – Shutdown/Restart a local or remote server via command prompt

Today’s post is not SQL Server related, but is related to the underlying host operating system and it’s administration. When working on development projects, one may need to restart servers and/or workstations often. This becomes a challenge when one is working from remote locations or on virtual machines hosted on the network.

Today, I will show how to shutdown or restart a local or remote machine via the command prompt. In fact, you may be surprised (as are most people around me) to learn that this functionality exists since Windows 2000 (i.e. it’s more than a decade old!)

Remote Shutdown tool – SHUTDOWN.EXE

The windows operating system ships with a remote shutdown tool. It is a command line tool that can be used to shutdown or restart local and remote machines. In Windows Server 2003, this tool has been enhanced to also accept the reason for the shutdown.

The syntax and help for this tool can be obtained by going to the command prompt on the machine and typing:

shutdown /?

The tool allows administrators to:

  • Shutdown or restart a local machine

    • Shutdown: shutdown /s
    • Restart: shutdown /r

  • Shutdown or restart a remote machine

    • Shutdown: shutdown /s /m \MyRemoteMachine 
    • Restart: shutdown /r /m \MyRemoteMachine

  • Schedule shutdown/restart operations

    • Shutdown: shutdown /s /t 200
    • Restart: shutdown /r /t 200
    • The above examples set a timeout of 200 seconds before the shutdown/restart takes place

  • Specify a reason for the shutdown/restart

    • Planned: shutdown /s /d p:xx:yy
    • Unplanned: shutdown /s /d u:xx:yy
    • Where xx is the major reason number and yy is the minor reason number. For example, a shutdown due to application installation should have a major reason code of 4 and a minor reason code of 2
    • User can also specify a custom comment by using the /c swtich

  • Abort a system shutdown

    • shutdown /a

  • Log off from a local machine (remote logoff is not supported)

    • shutdown /l

  • Hibernate a local machine

    • shutdown /h

  • Force the operation

    • shutdown /s /t 200 /d p:4:2 /f

Further Reading: http://technet.microsoft.com/en-us/library/cc780360(v=ws.10).aspx

Until we meet next time,

Be courteous. Drive responsibly.

[EDIT: April 25, 2013, 0215IST – rectified the option for Hibernate.]

2 thoughts on “#0252 – Shutdown/Restart a local or remote server via command prompt

  1. johan.parlevliet

    Thanks for sharing.

    I think there is a mistake: You have twice “shutdown /l” for logoff and hibernate,


  2. Nakul Vachhrajani

    @johan.parlevliet: You are correct. I have rectified the option for Hibernating a local machine. Thank-you for reading and glad that you liked it!



Let me know what you think about this post by leaving your feedback here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.