- Home ›
- Articles ›
- Restart or Shutdown Windows Computer Using CMD and SHUTDOWN Commands from the Command Line
Restart or Shutdown Windows Computer Using CMD and SHUTDOWN Commands from the Command Line
Restarting or shutting down a Microsoft Windows computer is relatively easy using the Command Line Interpreter (CLI), sometimes also called the command prompt or command line (CMD). This article shows you various ways to shutdown and restart computers using the CMD.exe and SHUTDOWN.exe commands.
Introduction
There are many reasons why you would want to shutdown and restart Windows or any other computer for that matter. Whether it be to have a quick way to schedule a shutdown or to restart computers remotely without having to manually shutdown the machine.
As a side note, if you would like to learn how to use the task scheduler you might want to have a look at: Schedule a Shutdown or Restart Computers Remotely
Using CMD.exe and SHUTDOWN.exe can help with your daily administrative tasks, and make your trips to the server room or another floor in your house a thing of the past. You’ve waited long enough here are the examples. But do look further down to check out the various command line options for CMD.exe and SHUTDOWN.exe.
Use SHUTDOWN.exe to Shutdown and Restart the Computer
The first thing we will want to do is open the command prompt (CMD). To do this, click on the Start > Run... and type cmd.exe. The command line interpreter will open.
We will now show you some simple examples on how to use the command line options available in SHUTDOWN.exe. All of the following commands should be executed at the command prompt or directly from the Run... dialog.
Shutdown the Local Computer Immediately
By default there is a 30 second delay with all SHUTDOWN commands, this at least gives you a short window to use the abort command to stop a shutdown if you’ve made a typing mistake. The /p takes down the machine immediately.
C:\>shutdown /p
Restart the Local Computer
To restart the local computer we would issue the following SHUTDOWN.exe command:
C:\>shutdown /r
If we wanted for the restart to begin immediately, we would use the /t 0 option. The /t 0 option ensures that a time-out period of 0 (zero) seconds is used before the command is executed. /t can be set between 0 and 600 seconds (0 and 10 minutes). In our case, this will execute the shutdown immediately.
C:\>shutdown /r /t 0
Shutdown the Local Computer with a Delay (time-out) Period of 10 Seconds
Similar to the above, however we use 10 instead of the 0 after the /t option. This will shutdown the computer after a 10 second time-out period.
C:\>shutdown /s /t 10
Shutdown a Remote Computer Immediately
The following command will execute an immediate shutdown of a computer named "myothercomputer". Please note that you must have administrative permissions on "myothercomputer". If you’re currently logged with a different credential, you may need to use the RunAs command to launch the command prompt (CMD):
C:\>shutdown /m \\mycomputer /s /t 0
Restart Remote Computer Immediately
The following command will execute an immediate restart of a computer named "myothercomputer", as in the previous example, make sure you’re logged on with credential that has local admin permissions on the remote computer:
C:\>shutdown /m \\mycomputer /r /t 0
Hibernate the Local Computer
The following command will execute a hibernation directive and will within 30 seconds begin a hibernation and shutdown action:
C:\>shutdown /h
Introducing CMD.exe
CMD.exe is the Microsoft Windows built-in command line interpreter. It has been bundled with Windows operating systems for quite some time and is standard on Windows XP, Windows Vista, Windows 7, as well as the server line of products: Windows Server 2000, Windows Server 2003 and Windows Server 2008.
CMD.exe provides a basic interface between the user/administrator and the operating system by using a text-only user interface. For people used to a GUI (Graphical User Interface) this may seem like a step backwards, why would anyone want to use a text only command line interface? The reason is quite simple, the command line interface (CLI) allows a quick way to perform repetitive tasks without having to sit there clicking a mouse. But the pros and cons of using a command line instead of a GUI is a whole other article :).
CMD.exe Command Line Options
The following listing shows all the command line options for CMD.exe:
C:\>cmd /?
Starts a new instance of the Windows command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using ! as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion.
Introducing SHUTDOWN.exe
SHUTDOWN.exe is a command which ships with most Windows operating systems. It can be run from the command line (CMD) to shutdown and/or restart the computer. SHUTDOWN.exe can be used to do more than just shutting down or restarting the computer, the following list shows extra functions:
1. Shutdown the computer.
2. Shutdown the computer after a certain time delay.
3. Hibernate the local computer.
4. Shutdown and restart the computer.
5. Shutdown and restart a remote computer.
6. Abort a system shutdown and/or restart.
7. Log off the current user.
8. Shutdown and restart the computer. After the system is rebooted, restart any registered applications.
9. Document the reason for an unexpected shutdown of a computer.
SHUTDOWN.exe Command Line Options
The following listing shows all the command line options for SHUTDOWN.exe:
C:\>shutdown /?
Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]
[/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]
No args Display help. This is the same as typing /?.
/? Display help. This is the same as not typing any options.
/i Display the graphical user interface (GUI).
This must be the first option.
/l Log off. This cannot be used with /m or /d options.
/s Shutdown the computer.
/r Shutdown and restart the computer.
/g Shutdown and restart the computer. After the system is
rebooted, restart any registered applications.
/a Abort a system shutdown.
This can only be used during the time-out period.
/p Turn off the local computer with no time-out or warning.
Can be used with /d and /f options.
/h Hibernate the local computer.
Can be used with the /f option.
/e Document the reason for an unexpected shutdown of a computer.
/m \\computer Specify the target computer.
/t xxx Set the time-out period before shutdown to xxx seconds.
The valid range is 0-600, with a default of 30.
Using /t xxx implies the /f option.
/c "comment" Comment on the reason for the restart or shutdown.
Maximum of 512 characters allowed.
/f Force running applications to close without forewarning users.
/f is automatically set when used in conjunction with /t xxx.
/d [p|u:]xx:yy Provide the reason for the restart or shutdown.
p indicates that the restart or shutdown is planned.
u indicates that the reason is user defined.
if neither p nor u is specified the restart or shutdown is unplanned.
xx is the major reason number (positive integer less than 256).
yy is the minor reason number (positive integer less than 65536).
Conclusion
This article presented an overview of the CMD.exe command line interpreter and the SHUTDOWN.exe command. It also showed examples of various ways to shutdown, restart local computers as well as remote computers/servers.
References
Schedule a Shutdown or Restart Computers Remotely
/articles/shutdown-or-restart-computers-remotely.aspx
[Permalink] - Updated: Sunday, February 21, 2010

Articles of Interest