Windows Server

Restart Windows Server 2003 from the command line

When the Windows Server 2003 computer you are working on will not shut down and you don't have any luck using the Start menu or the [Ctrl][Alt][Delete] methods -- and you need to restart the server as quickly as possible -- Derek Schauland can help you. Here is a quick workaround that gets the job done -- and you don't even have to handle power cords or the power switch.

The Windows Server 2003 computer you are working on will not shut down. You don't have any luck using the Start menu or the [Ctrl][Alt][Delete] methods, and you need to restart the server as quickly as possible. There is a quick workaround that gets the job done -- and you don't even have to handle power cords or the power switch.

From the command line, you can shut down or reboot any Windows Server 2003 computer (or even Windows XP or Vista machines) with the Shutdown.exe command. (Note: The exe file extension is optional for the Shutdown command.) Shutdown.exe contains a number of switches that allow you to specify different actions for the server when the Shutdown command executes. The Shutdown.exe switches are as follows:

/? Displays the Help listing
/i Displays the graphical user interface (GUI); it must be the first option
/l Logs off the current user; it cannot be used with the /d or /m options
/s Shuts down the computer
/r Shuts down and restarts the computer
/g Shuts down and restarts the computer and then restarts any registered applications
/a Aborts system Shutdown
/p Turns off the local computer with no timeout or warning
/h Hibernates the local machine
/e Documents the reason for shutting down the computer
/m Specifies the target computer; it is used with \\computername
/t xxx Where xxx is the number of seconds before Shutdown
/c "comment" Where "comment" is the reason for the Shutdown or restart
/f Forces running applications to close without warning users
/d [p|u:]xx:yy Provides the reason for the Shutdown action: p = planned; u= unplanned; xx supplies the major reason code; yy = supplies the minor reason code

When you enter a Shutdown with no arguments, the Help listing will display. The Help listing also includes the reason codes available for use with the /d switch. The reason codes are shown below:

Reasons on this computer:
E=Expected U=Unexpected P=Planned c=Customer Defined
Type Major Minor Title

 

 

 

 

U

0

0

Other(Unplanned)
E

0

0

Other(Unplanned)
EP

0

0

Other(Planned)
U

0

5

Other Failure: System Unresponsive
E

1

1

Hardware: Maintenance(Unplanned)
EP

1

1

Hardware: Maintenance(Planned)
E

1

2

Hardware: Installation(Unplanned)
EP

1

2

Hardware: Installation(Planned)
P

2

3

Operating System: Upgrade (Planned)
E

2

4

Operating System:

Reconfiguration (Unplanned)

EP

2

4

Operating System:

Reconfiguration(Planned)

P

2

16

Operating System:

Service Pack (Planned)

U

2

17

Operating System:

Hotfix (Unplanned)

P

2

17

Operating System:

Hotfix(Planned)

U

2

18

Operating System:

Security Fix(Unplanned)

P

2

18

Operating System:

Security Fix(Planned)

E

4

1

Application: Maintenance(Unplanned)
EP

4

1

Application: Maintenance(Planned)
EP

4

2

Application: Installation(Planned)
E

4

5

Application: Unresponsive
E

4

6

Application: Unstable
U

5

15

System Failure: Stop Error
E

5

19

Security Issue
U

5

19

Security Issue
EP

5

19

Security Issue
E

5

20

Loss of Network Connectivity

(Unplanned)

U

6

11

Power Failure: Cord Unplugged
U

6

12

Power Failure: Environment
P

7

0

Legacy API Shutdown

You can use many of these switches in conjunction with one another when issuing the Shutdown command. A usage example for the Shutdown command follows:

Shutdown /r /c "Hanging Application or service" /t 30

This example would restart the local machine storing the comment provided with the /c switch. Windows would wait 30 seconds before initiating the restart. You might also create a batch file to use when it is necessary to restart a server in a remote location. The batch file might look like this:

Shutdown /m \\computername /r /c "Remote Restart" /t 45

By saving this command in a batch file, it can save you time if you routinely restart the same remote server.

Miss a Windows Server 2003 tip?

Check out the Windows Server 2003 archive to get even more Windows Server 2003 tips.

Stay on top of the latest Windows Server 2003 tips and tricks with our free Windows Server newsletter, delivered each Wednesday. Automatically sign up today!

About

Derek Schauland has been tinkering with Windows systems since 1997. He has supported Windows NT 4, worked phone support for an ISP, and is currently the IT Manager for a manufacturing company in Wisconsin.

31 comments
jarrod2
jarrod2

THANK YOU! I'm working remote 2states away and needed this thing to restart. I've never run into this issue before. saved me.

curt
curt

Great to have in an east-to-use table. I can't count the number of times I have had to ask a co-worker: "Hey, what switch do I use to ..." when doing a remote restart of a client computer. It may be old, but it's sure handy!

kmmohd_anwar
kmmohd_anwar

How to restart server when the server get hang and keyboard and mouse got hang .I had clicked ALT+CTRL+DEL but no response .Is there any command to restart

dtrivison
dtrivison

The tool PSSHUTDOWN also an exe works a lot better than the built in shutdown exe. It is actually reliable which shutdown exe is not.

OregonLighthouse
OregonLighthouse

If you are going to be shutting down any system processes in Task Manager to track down a potential problem (like svchost for instance), it's handy to have a command-line window already up with "shutdown /a" at the ready... that way, if you accidentally terminate a task that results in the automated "The system will restart in 15 seconds" message, you can simply abort it and often just restart the process without any downtime. I found this useful when I ran across a virus a few years ago that renamed itself svchost.exe and ran as a process... since there are often half a dozen svchost.exe's listed, it was easy to kill the real one (and thus initiate an automatic shutdown) by mistake. (And happy ending... when I finally killed the bug-version, it allowed me to kill the entire virus without having to shutdown the server).

OregonLighthouse
OregonLighthouse

Just in case anyone else tried to print this... the text prints (I tried both paper and PDF) but not the tables. Cut and paste time... whee!

briansa
briansa

If you're a server admin and this is the first time you've heard of this utility you need to go choose another profession. I've been using this utility for over ten years now...

JustFishin
JustFishin

Sorry - shoot me down if you want, but if any sys-admin worth his salt doesn't already know this should be looking for a career change.

gregberry
gregberry

Works with XP, but you need to use a - instead of a / for the switch

tundraroamer
tundraroamer

Except for reason codes, the shutdown command has been around since NT. I could remote in to reboot any of those servers as needed. It's a handy command to save a trip in just to poke a button. Still had to do that on occasion...

Photogenic Memory
Photogenic Memory

Well, not really but Windows 98 did allow you to warm boot the OS without rebooting the hardware. This is waht you do: 1.)Click the start button and proceed to bring up the shutdown menu. 2.) Click the restart toggle option. 3.) Finally, hold down the shift key and immediately release it once you click the "OK" button. Windows 98 will do a warm-boot instead of fully going down. As much as I like issuing commands from the command-line in XP/Server 2003; I do miss this ability from Win98. P.S. You can't do this in Win2K either.

jleather
jleather

I have also used these commands as icons on my desktop, i.e. a restart and a shutdown icon. This saves you from going to start etc. As for the actuall icons I found some good ones in shell32.dll. In a tangent to this, I also have a lock screen icon with the following command: %windir%\system32\rundll32.exe user32.dll,LockWorkStation and use a icon with a key from shell32.dll. BTW I am using XP. Hope someone finds this useful, John

duke.url
duke.url

Something is wrong with the document - the tables regarding the command line parameters and reason codes don't print.

gary_horne
gary_horne

Hey, I've been using command line restart for just over a year now. It works great! I do have one question...how to 'import' a list several computer names at one time?? I'd like to reboot or shutdown all my systems if necessary.

Justin James
Justin James

This begs the question... if the system is so locked that CTRL+ALT+DELETE won't bring up its dialog, can I even reach a command line? Sadly, too many times the answer to this is "no". That being said, these situations are rare and far between now-a-days, and this is always a good thing to try anyways. Its ability to shutdown remote computers is also much appreciated. J.Ja

bjones
bjones

This works as long as the RPC service on the remote target machine is still running properly. Also, great tool when a user wants to get lippy.... -t 0 works wonders.

RoyB
RoyB

I've been using this command since I started managing my servers and WinXP workstations via RDC - haven't really seen my servers since I put them in the rack last year. I've found that I have to put the FQDN in after the /m switch (have the canned syntax in a text file). Still works great!

Master G
Master G

Nice list!! I just did that to my domain controller when I was having porblems rdp'ng to it. Of course I replicated before doing that so it does not affect the users. But it's nice to know this list - You can use the interface to shutdown/restart as many system as you need shutdown -i is a neat app! Thanks for the post.

Dumphrey
Dumphrey

And it was good to see all the switches and reason codes so nicely laid out. My only question is what determins a registered application to be restarted with the server? Surly if they are set to boot with the server, you would not need a switch in the shutdown command?

hanoch
hanoch

hey - thanks ...! nice and working tip . Dan.

samson99tx
samson99tx

When you enter the command line from any workstation on the domain,type shutdown.exe -i This brings up a GUI for the remote shutdown, and you can do a "browse" for other machines on the domain. You can also choose from several "reasons" for shutdown, and add your own comments. I do have a bacth file for shutdown.exe -i, and made my own icon in MS Paint as a lightning bolt. This will also find any server or machine in the Active directory on the domain.

Justin James
Justin James

The command is "shutdown -r" from the command line. But if your mouse & keyboard are also hung, how are you going to enter a command? If you computer is that hung, you need to power it off completely. J.Ja

amabilis
amabilis

...is also able to read servernames from a textfile.

aaronjsmith21
aaronjsmith21

I am not completely sure, but I think every Win Version from XP on that use the Shutdown command needs to have the "-" instead of the "/" for the switches to work. I am not sure why then the help for the command still has "/" in it, that is Microsoft for ya, even the simple things are screwy. I have tested this in XP (All), 2003, Vista & 2000 Pro (I downloaded it to 2000 Pro). I think the server editions of 2000 already have it. I am not sure. Have not used 2000 Servers in a while now, and I do not recall if I had to download it for them also.

OregonLighthouse
OregonLighthouse

I've been using Shutdown also since the NT days, but I'm one of those types who likes to keep handy little tables like this around for quick reference (is it me, or does command-line help still suck after nearly 30 years of DOS? Oh well, better than the help in Cisco IOS I guess).

aaronjsmith21
aaronjsmith21

Create a batch file for this purposed! All you have to do it have the command for each computer on a new line in notepad, you have to write out each command completely, then you have to click on File > Save As and then with the quotes type in "yourfilename.bat" and save it where you want, then all you have to do is double click on it and it will run. If you need more information on how a batch file works, Google it, just type in "batch commands" in Google and you can figure it out from there.

patrick.lamb
patrick.lamb

It's got one line: at \\%1 %2 shutdown -r -t 0 -f When I want to schedule a restart of a machine I go to a command prompt and type "sd (the name of the batch file) machine time"!

itadmin01
itadmin01

Create a Scheduled Task with "C:\WINDOWS\system32\shutdown.exe -r -f -t 01" in the Run Command. Make it restart weekly just to "refresh" now and then anyway, to minimize server lock ups in the first place. If you ever lose control of your Task Manager anyway, just go to your Scheduled Task and run it to reboot.

amabilis
amabilis

ROFL - as administering some Linux-servers I did not even thought about of rebooting prophylactically. Crazy Windows-world :-)