One of the most irritating aspects of Windows servers are Windows Updates. Simple software updates require a full reboot of the machine, keeping these servers a pale shadow of their Linux/BSD-based counterparts.
Regardless of my personal opinions, we have several Windows servers at work that require a reboot every month. Our operating hours make off-hour maintenance a chore (the maintenance window starts at midnight), so I wanted to try scheduling a reboot with the task scheduler.
Harder than you'd think.
The windows permission system is hard to parse, and it took several attempts to get this to work successfully. Here are the details of the scheduled task I use to reboot servers after hours.
Creating the task
- In task scheduler, right-click on "Task scheduler library" and select "Create Basic Task"
- You may name it and describe it however you like. I specify it's a Windows Update reboot task, and then grumble about Windows in the description. YMMV.
- For trigger, I select "One time", and pick a time a hour or so after we close; when I'm sure no one will get kicked off the server.
- For action, pick "Start a program"
- When it comes to pick the program, pick "
C:\Windows\System32\shutdown.exe" and put in "
/r /f /t 60 /d p:02:18 /c "Rebooting for Windows Update"" for arguments. This means:
/r: Reboot, instead of shut down
/t 60: Wait 60 seconds, just in case you need to abort the shutdown (with
/d p:02:18: Provide the reason for shutdown. p:02:16 = planned shutdown for security hotfix
/c "…": Put your snarky comment here
Great, your scheduled task is all set! And if you leave it there, it will most likely fail.
To make sure this task actually does what it's supposed to, you need to check the settings of the scheduled task.
- Right-click on the task and select "Properties". Not "Run". Don't accidentally restart your server.
- Press "Change the user or group", and switch it to "SYSTEM"
- Check the "Run with highest privileges" box
If all goes according to plan, your server should now be able to reboot off-hours. One less pain to deal with when it comes to Windows administration!
Tags: windows server