Windows shutdown command

Let’s say you need to shut down or reboot your computer from a command line, a batch file, or a desktop shortcut. Maybe you want to shut it down right now, or in an hour. You can do all of that and more with the Windows shutdown command, shutdown.exe.

What’s the Windows shutdown command good for?

windows shutdown command
You can automate this with the Windows shutdown command, which has lots of options.

There may be several reasons you’d want to do it. I know someone who uses it to reboot a computer because a bug in Flash keeps Windows from hibernating properly if you’ve ever run Flash in that session. I used it a ton when patching large quantities of machines. I’d just deploy patches whenever I had time to deploy them, suppress the mandatory reboot, and then when downtime was scheduled, I’d reboot the machines in an orderly fashion using either a command line or batch files.

I wish I’d thought of that trick back in my days when I had one 36-hour window per year to patch and reboot 100 servers. That would have made 2003, 2004, and 2005 happier years. Or at least it would have made one weekend each of those years a lot better. But I didn’t. I thought of it in my days when I had to patch and reboot a couple hundred servers once a month, every month. If I didn’t want some server, somewhere, to be down every single day, that was the only way to do it.

The Windows shutdown command can be a lifesaver if your job involves patch management.

Windows shutdown command options

Here are some useful options:

shutdown /r reboots the computer.
shutdown /s does a hard shutdown and power off, if the computer supports it. Most computers made in the last 20 years or so do.
shutdown /t ??? allows you to specify how many seconds the computer should wait until shutting down or restarting. shutdown /t 3600 shuts the computer down in an hour. The default is 30 seconds, and I don’t recommend setting it much lower than that as 30 seconds is about how long it takes to abort an accidental shutdown.
shutdown /m \\computer shuts down a remote computer. That’s how I was able to remotely reboot hundreds of computers in a controlled, orderly fashion.
shutdown /h forces the computer to hibernate, if the computer supports it.
shutdown /a aborts a previously scheduled shutdown. I never, ever, ever do an immediate shutdown, to give myself time to issue the abort command if necessary. Maybe you changed your mind. Or it’s the wrong computer. Sometimes you specify power down when you should have specified something else. (That’s called “bruce-ing,” after a guy named Bruce who had a tendency to shut down computers accidentally when he meant to log off, then say Dave must be patching or something. Don’t bruce your computer.)
shutdown /g restarts any registered applications after coming back from reboot. Nice option.

You can combine options as desired. You can issue shutdown commands from a command prompt, from a batch file, or from a desktop shortcut. Whatever is most convenient for you.

Finding out what options your version supports

Not all options are available in all versions of Windows, so type shutdown /? at a command prompt to get a summary of options available on your computer.

It’s a very good idea, if you have a batch file containing shutdown commands, to warn the user with an echo command and a pause command that the script is doing to shut a bunch of computers down. That gives anyone who runs it a chance to hit ctrl-c to cancel it.

Sample scripts using the Windows shutdown command

Here’s a sample batch file that shuts down the computer in an hour.

echo This script will shut down the computer in one hour. Hit ctrl-c if you ran this by accident.
shutdown /t 3600

Add the /h parameter to the shutdown command in line 3 of the script to make the computer hibernate instead of shutting down.

Want a shortcut that shuts the computer down, no questions asked? Just right-click on the desktop, select New, then Shortcut. Type shutdown, then click Next. Click Finish. Now right-click on your new shortcut, select Properties, and inside Target, type your parameters (like /a to abort, /t 3600 to shut down in an hour, etc.).

I prefer to use it in batch files, since I can use pause commands and use it to verify I’m doing what I want to be doing. But it’s certainly not a bad idea to keep a shortcut that does a shutdown /a handy if you use these a lot–perhaps pinned to the start menu–so you have an emergency cancel switch.

%d bloggers like this:
WordPress Appliance - Powered by TurnKey Linux