- Back to Home »
- Tips and Tricks , Windows Tip »
- Windows Tip: Shutdown Your Computer With The Command Prompt
Tuesday, October 4, 2011
This is one of my favorite tricks, shutting down my Windows XP machine with one simple line of code!
This might not seem necessary since the power button is tucked neatly inside the Start Menu, but this trick has a few more uses. Not only can you use this on your machine, but on network machines as well – as long as you have administrative access! You can also restart machines, set comments (the reason for the shutdown), specify time and more!
List Of Shutdown Command Switches
No Switches | Display information about the shutdown command, same as typing “-?” |
-i | Display a GUI. It must be the first switch |
-l | Log off the user (This cannot be used on a remote machine: “-m” switch) |
-s | Shutdown the computer |
-r | Restart the computer |
-a | Cancels a system shutdown already in progress |
-f | Forces running applications to close without warning |
-m \\computername | Instruct a remote computer to shutdown (can be used with the restart & abort switches) |
-t xx | Set a given time for shutdown, in seconds |
-c “comment” | Shutdown comment (maximum of 127 characters) |
-d [u] [p]:xx:yy | The reason code for the shutdown: u is the user code p is a planned shutdown code xx is the major reason code (positive integer less than 256) yy is the minor reason code (positive integer less than 65536) |
How To Use Shutdown Switches:
You don’t have to use them all, but the switches you do use must be in the following order:
shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]
How To:
Open the command prompt: Windows Key + R then type the command below and hit OK:cmd
This will open the command prompt. Now we can play!
Note: You could type the shutdown command directly into the Run dialog. I don’t advise this. If there is a typo or error, you won’t know. There is no information given!
Shutdown Local Machine
This only takes a couple of keystrokes. Type the code below and hit OK:shutdown -s
“shutdown” tells the computer what command we want to execute and the “-s” switch tells it what to do, which is to shutdown!
Specify Time
shutdown -s -t 60
Now we have added the “-t” switch and a variable, which in this case is “60″. This number is the number of seconds before the computer is shutdown. A dialog will open and display a count down timer!
Give Us Some Info!
shutdown -s -t 120 -c "You better finish, because I shut you down foo!"
The “-c” switch will allow you to give the user some information for the reason of the shutdown.
Shutdown A Remote Computer
shutdown -s -m \\desktop -t 45
I really like this one! The “-m” switch will allow you to shutdown a remote machine, in this case, a computer named “desktop”. For this to work, you must have administrative access to the computer! To see of you do, hit Windows Key + R then type the computer’s name, i.e.:
\\desktop
If you can connect to it, you will be asked to log into the machine with a user name and password. Once confirmed, a window will open displaying the directories available to you. Now you know you can shut it down remotely.
Cancel Shutdown
Let’s say that you need to cancel a shutdown in progress. Go to the computer in question, hit Windows Key + R then type command below:shutdown -a
This will abort the shutdown, assuming there is a counter and it hasn’t reached zero yet!
Shutdown Command via Dialog Window
Typing commands in a DOS window is not what most computer users want to fool with so I’m going to start by showing you how to use the dialog window to use the shutdown tool.
To open the dialog window click start, click run, type cmd and press enter. A black DOS looking window will open. Type shutdown -i and press enter. A window similar to the one below will popup.
Under computers type the network name of the computer you want to shutdown, restart, or logoff. In this example I will use \\yourcomputer. You can use your computer’s name to try the commands on your computer if you like.
If you don’t know a computers name right click my computer, select properties, select the computer name tab. Your computer name is listed next to full computer name.
To send these commands to other computers across your network you need to have administrative privileges on those computers. An easy way to see if you haveadministrative privileges on a networked computer is to try browsing to it. Click start, click run, type \\yourcomputer (replace yourcomputer with your computer’s name of course) and press enter. If you are able to access the computer you will be able to send shutdown commands to it. If you get asked for a password or it denies access you don’t have administrative privileges and you won’t be able to send shutdown commands to that computer.
In this example I’m going to shutdown computer \\yourcomputer on my network. Before it shuts down it’s going to show a message for 20 seconds.
The first thing you need to do is add which computer you want to shutdown. Clickadd and type your computer name in the add computers box.
You can send the command to multiple computers by pressing enter after the name of each computer and typing the name of the next computer on the next line. Each computer needs to be on its own line.
Click OK when you are finished adding the computer(s) you want to send the command to.
Under what do you want these computers to do: tell it to shutdown, restart, or logoff.
If you want a box to popup on the computer(s) you are sending the command to that lets them know the computer is about to shutdown, restart, or logoff in X many seconds leave warn users of the action checked off. If you want to change how many seconds to countdown before performing the action you can change that next to seconds.
You can tell a user on the computer you are about to perform the action on why you are performing that action by typing your message in under comment.
Click OK to send the command to the computer(s).
If you get an error when sending the command it will look like the one below.
Shutdown Command via Command Prompt
The shutdown command becomes more flexible and automated when used from the command prompt. To run the shutdown command from the command prompt, go tostart, run, type cmd, and press enter. In the black box (the command prompt) typeshutdown and the switches you want to use with the shutdown command. You have to use at east one switch for the shutdown command to work.
The Switches
The shutdown command has a few options called switches. You can always see them by typing shutdown -? in the command prompt if you forget any of them.
-i: Display GUI interface, must be the first option
-l: Log off (cannot be used with -m option)
-s: Shutdown the computer
-r: Shutdown and restart the computer
-a: Abort a system shutdown
-m \\computername: Remote computer to shutdown/restart/abort
-t xx: Set timeout for shutdown to xx seconds
-c “comment”: Shutdown comment (maximum of 127 characters)
-f: Forces running applications to close without warning
-d [u][p]:xx:yy: The reason code for the shutdown u is the user code p is a planned shutdown code xx is the major reason code (positive integer less than 256) yy is the minor reason code (positive integer less than 65536)
-l: Log off (cannot be used with -m option)
-s: Shutdown the computer
-r: Shutdown and restart the computer
-a: Abort a system shutdown
-m \\computername: Remote computer to shutdown/restart/abort
-t xx: Set timeout for shutdown to xx seconds
-c “comment”: Shutdown comment (maximum of 127 characters)
-f: Forces running applications to close without warning
-d [u][p]:xx:yy: The reason code for the shutdown u is the user code p is a planned shutdown code xx is the major reason code (positive integer less than 256) yy is the minor reason code (positive integer less than 65536)
Please note: I’ve noticed using a switch with a – sign doesn’t work sometimes. If you are having trouble try using a / in place of – in your switches.
Examples
shutdown –m \\computername –r –f This command will restart the computer named computername and force any programs that might still be running to stop.
shutdown –m \\computername –r –f –c “I’m restarting your computer. Please save your work now.” –t 120 This command will restart the computer named computername, force any programs that might still be running to stop, give to user on that computer a message, and countdown 120 seconds before it restarts.
shutdown –m \\computername –a This command will abort a previous shutdown command that is in progress.
Using a Batch File
You can create a file that performs the shutdown command on many computers at one time.
In this example I’m going to create a batch file that will use the shutdown command to shut down 3 computers on my home network before I go to bed.
Open notepad and type the shutdown command to shut down a computer for each computer on the network. Make sure each shutdown command is on its own line. An example of what should be typed in notepad is below.
shutdown –m \\computer1 –s
shutdown –m \\computer2 –s
shutdown –m \\computer3 -s
shutdown –m \\computer2 –s
shutdown –m \\computer3 -s
Now I’ll save it as a batch file by going to file, save as, change save as type to all files, give the file a name ending with .bat. I named mine shutdown.bat. Pick the location to save the batch file in and save it.
When you run the batch file it’ll shutdown computer1, 2, and 3 for you.
You can use any combination of shutdown commands in a batch file. I just used the one above as an example.
Still need help? Ask your computer question now.
thank you