Schedule Windows server to reboot or shutdown automatically

by LinuxTitli · 36 comments

Sometime it is necessary to reboot (or shutdown) windows server. Under UNIX or Linux you can use reboot / hal t/shutdown command via cron jobs or at command. But, when it comes to Windows server there is no built in command exist. Only Windows 2000 Resource Kit offers shutdown command line utility.

However, sysinternals has nifty utility called PsShutdown. It is a command-line utility similar to the shutdown utility from the Windows 2000 Resource Kit, but with the ability to do much more. In addition to supporting the same options for shutting down or rebooting the local or a remote computer, PsShutdown can logoff the console user or lock the console (locking requires Windows 2000 or higher). PsShutdown requires no manual installation of client software.

How do I schedule Windows Server Reboot / Shutdown?

You can download PsShutdown from sysinternals web site.

Store file on Windows server in folder. I use folder called C:\admutils. Next open windows command prompt (Start > Run > cmd) and use windows at command to schedule reboot:
c:> at 2:00am c:\admutils\psshutdown.exe -r -f -c -t 10
Above command will reboot system at 2am. If you want to shutdown system:
c:> at 1:00am c:\admutils\psshutdown.exe -s -f -c -t 10
Where,

  • -s: Shutdown windows server
  • -r: Reboot windows server
  • -f: Forces all running application to exit
  • -c: Allow the shutdown to by cancel by user
  • -t: Specifies the countdown in seconds until the shutdown

For more information read official psshutdown documentation. Read at command help by typing at /? command.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 36 comments… read them below or add one }

1 Anonymous 05.26.06 at 1:52 pm

Excellent information, I thought you guys only likes UNIX / Linux ;)

Keep it up good work.

2 Anonymous 09.13.06 at 9:16 pm

Windows server already includes a shutdown command called just shutdown!

3 Anonymous 09.13.06 at 9:17 pm

Ok I will try reading the post next time

4 TimBee 01.17.07 at 2:02 pm

You should also add the command “-accepteula” to the psshutdown command, because otherwise the task will hang, idicating a “running” state in Scheduled Tasks. It’s just waiting for the EULA agreement, which it doesn’t show.

So, to complete the example before, type:

“at 2:00am c:\admutils\psshutdown.exe -r -f -c -t 10 -accepteula”.

5 nixcraft 01.17.07 at 10:21 pm

@TimBee,

Thanks for pointing out this issue.

Appreciate your post.

6 TimBee 01.18.07 at 8:45 am

NixCraft -> Thank YOU for this helpful article! :-)

7 Weenie 03.06.07 at 12:28 pm

great. I was experiencing problem with shutdown built-in command.
just discovered this website, looks very interresting.

8 Dan 04.10.07 at 7:42 pm

What switch do I need to do a weekly restart?

9 nixcraft 04.11.07 at 2:31 pm

Dan,

Use windows schedule task option and select weekly option.

10 Mani G 04.15.07 at 1:40 pm

Nice article.. It has helped me a lot. Thank you.

11 Les W 04.24.07 at 1:05 pm

Thank you. A very usful bit of information, just what the doctor ordered.

12 Jeff Smith 05.14.07 at 10:58 am

a’noon everyone.I am running, win server2003. I have tried… the above. and it does nto work for me-I must be doing something wrong. I have typed the following. in the cmd prompt. C:\>at 11:45am c:\pstools\psshutdown.exe -r -f -c -t 10
I press enter and I get the following message. “Added a new job with job ID = 1″
NOTHING happens….at the said time…!!!! what am I missing? the official documentation, states that I have to put in the comp name? is this what I am missing???? please help. many thanks, J

13 Jeff Smith 05.14.07 at 10:59 am

PS: how can I view these said jobs as well? I now apparently have 3 jobs pending.thanks. J

14 Jeff Smith 05.14.07 at 11:09 am

There is no need to reponde to my 1st message, I never saw the add -accepteula part. It now seems to work. Blindin, thanks. Can I get some script to make this run daily, without any manual intervention.

15 vivek 05.14.07 at 12:02 pm

Use the task scheduler in Windows 2000/2003 server by visiting My Comp > Control Panel > Scheduled Tasks

HTH

16 Jeff Smith 05.14.07 at 12:33 pm

yea thanks-I found that….im just being thick.monday morning hang over :).thanks

17 cornel panceac 05.25.07 at 10:48 am

for the ones who wonder, it looks like ’scheduled tasks’ is just a frontend to at, so if you wanna schedule some tasks, you can also use at /? to find out how :)
of course you’ll find out that entering just
at
will display the current jobs
at /delete
will delete the thing and so forth :)
happy hacking 2 all :)

18 cornel panceac 05.25.07 at 6:05 pm

testing today the command, i’ve found that -accepteula is not a supported parameter on recent version of psshutdown, as jeff smith pointed earlier

19 Rod 06.14.07 at 7:35 am

Works great with -accepteula, thanks

20 Andy Duncan 12.28.07 at 12:59 pm

I tried it with the accepteula switch and it still did not work……………….I am using windows 2003 server and R2

21 Andy duncan 12.29.07 at 3:45 am

My mistake i had to update to the latest version of the tool once i did that the -accepteula worked fine

22 Joe H 05.09.08 at 7:55 pm

You can also do this through Scheduled Tasks. Go to Control Panel->Scheduled Tasks->Add Task. Select Browse and go to %Windows%\System32\ and select shutdown.exe. You can then follow the wizard to select how often and at what time. You’ll need to provide account login info that has admin privileges on the machine. At end select the option to display advanced properties. Under the Task pane you’ll see it is going to run C:\WINDOWS\system32\shutdown.exe. You can add the /r option to restart – or any other you may need such as /t 60 to wait 60 seconds before restarting.

23 AD108 05.27.08 at 12:10 pm

/accepteula works with latest ver. of psshutdown.
Would also recommend psshutdown over Windows shutdown.exe
Open Notepad, paste the command below
psshutdown -r -f -c -t 10 /accepteula
then save as autoreboot.bat
Next create Windows scheduled task to run this batch file. Can download psshutdown.exe from sysinterals site and place in system32.

24 JP 06.04.08 at 9:33 am

sir,
My situation is some what different

I have server one is win2k3 and other is linux RH AS4 . what i want is both server should switched on morning 8 am and should shutdown 12 pm automatically how to make it ?

I tried but i could not succeed

Please write and explain simple way

25 Matt 06.06.08 at 7:06 pm

I’m looking for a way if possible of using the shutdown command or psshutdown command to restart a windows server 2003 without it causing services like exchange etc to report errors in event log of it not closing correctly and server logs reporting that the server shutdown unexpectedly, as this can lead diagnosing problems astray. Obviously the fact that it forces services to close mid operation is the problem – would the t switch fix this giving services enough time to stop or does it not start closing things until the time is up… I guess worse case is to run a stop command for services having a problem but it would be nice if there is just a simple switch for it
thanks

26 vivek 06.06.08 at 7:31 pm

Matt,

You need to write a small batch file. To stop service use net stop service command. May be something as follows will do the trick:

net stop "service name"
net stop "service name2"
at 1:00am c:\admutils\psshutdown.exe -s -f -c -t 

HTH

27 jw 06.14.08 at 3:11 pm

thanks for the info, very usefull!
My boss asked me to write a script to shut down the entire serverpark at work, in case of emergencies. I want to make a netstop script for shutting down several services quickly, to make sure the servers dont take too long to shutdown. As there are some exchange services that can give you a hard time when you ask them to shutdown for example. So i not only need to make these net stop scripts for exchange, but also for SQL, ISA and IIS servers. So if anyone of you familiar with scripting and services can help me .. it will be greatly appreciated! The best way to contact me is mailing me on “jannick.werckx@hotmail.com”. I hope to get some feedback, i really need these scripts. Thanks in advance!

28 Ken Wallewein 09.07.08 at 5:50 pm

Couple of comments on stopping services.
- It makes no sense to use an “at” command in a batch script. The script itself needs to be scheduled.
- It may be that the amount of time Windows allows for shutting down services needs to be extended. There’s a registry parameter for that; don’t remember where, offhand.

And one comment on scheduled tasks in general:
I like to have anything like this write to a log file so I see the record of what the command(s) did. Not a big fan of mysteries when it comes to server admin.

29 sampath kumar 10.23.08 at 5:34 am

sir,
My situation is different

I have server one is win2k3. I finished setting inthe scheduled task to shutdown the machine at 8.30 pm. Actually now what i want is my server win2k3 should switched on in the morning 8 am without manually switched on.

automatically how to make it ?

I tried but i could not succeed

Please write and explain simple way

30 josh 01.22.09 at 7:13 am

there is a shutdown command on windows 2003 which is used like
shutdown /t 00 /r
meaning shutdown in 00 seconds , reboot, to shutdown instead of reboot simply use /s, to force use /f

on winxp this tool exists but uses dashes ie
shutdown -t 00 -r

if your looking to startup a box, check your bios for auto power on scheduling. or use a scheduleld wake on lan from another system.

31 uddika 04.17.09 at 3:56 am

nice work guys, thanks v much

32 Gazzaman22 06.26.09 at 2:22 pm

Can any tell me and explain how to reboot windows 2000 server frequently
using this or another method
thanks

33 Venomhed 08.24.09 at 7:38 pm

Guys SHUTDOWN.EXE does NOT work under a Scheduled Task without a user logged in so please stop posting that it does.

PSShutdown DOES work as a scheduled task with no user logged in.

There is a difference, read and test before posting as to avoid confusion here.

34 Dan 09.15.09 at 6:26 pm

The latest version of PSShutdown pops up a license agreement which has to be accepted. Unfortunately, this has to be accepted on a per-user basis, even when running under the SYSTEM account. You’ll know it is waiting for the EULA to be accepted when you see PSShutdown.exe running forever.

To work around this problem, you can add an entry to the SYSTEM account’s registry indicating that you have accepted the EULA. Go to the key at HKEY_USERS\S-1-5-18\Software\Sysinternals\PsShutdown. Create it if it doesn’t exist (it should be there if you tried running it once before). Add a new DWORD value called EulaAccepted. Set this value to 1. Now you can schedule the task to run as described above and it will work.

35 Brad 11.23.09 at 1:52 pm

So Dan are you saying that the
/accepteula switch mentioned numerous
times above is not enough and that the
registry key needs to be changed/created?

36 Aziz 01.10.10 at 6:43 am

Hi there
i have a problem that how can i give a time for server 2003 to start automaticaly.
please help me.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: