Brian has been doing an awesome job of covering several neat things you can do with Windows Task Scheduler. One more: scheduling Windows to wake or sleep automatically at a particular time. Why would you want to do this? I don’t know about you, but for me, I was using my desktop Windows 7 PC as a file server for some time. Rather than sending wake-on-LAN packets every time I wanted to access a file on my Windows file server, I decided to leave the thing on from 10 AM to 10 PM every day. This was a compromise between waking up on demand and leaving my computer on 24/7 (sorry, environment).
There are third-party power management programs that do this, many of which come bundled with laptops. But if you are on a plain vanilla Windows desktop, you may want just to go ahead and do it natively. Here’s how:
1. Disable hybrid sleep / hibernation. (Optional, but recommended)
How to Disable Hybrid Sleep / Hibernation in Windows
The first step is to disable hybrid sleep and/or hibernation on your computer. Why would you want to do this?
Hibernate is a power-saving feature that saves your machine’s state (including unsaved documents, program states, etc.) onto your primary hard disk instead of onto the RAM (as sleep does). The tradeoff is slower resume time, but less power draw. This is important for laptops with batteries, but not so much for desktops. Hybrid sleep does both—it saves open documents and application states into the memory and the hard disk. This is so you won’t lose anything in case of a power outage.
But the real issue is that sometimes, hybrid sleep / hibernation can interfere with an automated wake script, depending on your configuration. In my case, waking from hibernation from a script only half worked—the computer would turn on, the fans would spin, and I’d get stuck on the “Resuming Windows” screen forever. If you have similar problems, you might just want to disable hibernation / hybrid sleep altogether. Here’s how:
Open a command prompt as an administrator. To do this in Windows 7, click the Start button, type Cmd and then right-click cmd.exe and choose Run as administrator.
Type powercfg -h off and press Enter.
If the command was successful, then you’ll get no error messages.
If you get the error message: “You do not have permission to enable or disable the Hibernate feature.” then re-read the previous step about running cmd.exe as an administrator.
Now, like a bear addicted to espresso, your computer will no longer hibernate. It’ll sleep, but it won’t hibernate. Mission accomplished.
For more information on Hibernation vs. Sleep, read this write-up that Austin did on the subject: Understanding Your PC And Devices, Sleep VS. Hibernate [groovyTips]
How to Create a Batch (.bat) File to Put Your Computer to Sleep
The way we’ll put your computer to sleep is by running a script (.bat) that will initiate the sleep command. By using a batch file, you can add other parameters and commands to it later without rejiggering your Windows Task Scheduler task.
To create a sleep batch file open up Notepad and type the following:
Rundll32.exe Powrprof.dll,SetSuspendState Sleep
Click File –> Save As… Under Save as type… choose All files *.* and give your file a name lie sleep.bat (or something else with a .bat extension).
Got it? If not, you can just download the sleep and wake batch files I already created by clicking here.
How to Create a Batch (.bat) File to Wake Your Computer
There isn’t a command line command to wake your computer. That’s because if you are in a position to be running commands, then your computer is obviously already awake. But what we can do is create a batch file with something arbitrary in it and then tell Windows Task Scheduler that it can wake the computer to run it. So, go ahead and make a batch file that does something like “echo Hello!” and then save it as wake.bat.
Again, you can also just download our sleep / wake batch files here.
How to Schedule Your Computer to Sleep and Wake at a Certain Time
Now that we have batch files to sleep and wake our computer, all we need to do is tell Windows when to run them.
Run Task Scheduler. The fastest way to get to it is by clicking the Start button and typing Task Scheduler.
Click Action and then Create Task… In the General tab, give it a name like “Sleep.”
In the Triggers tab, click New… Set the task up to begin the task “On a schedule” and choose daily and plug-in the time when you want it to run. Click OK.
Your trigger will be enabled.
Next, click the Actions tab and click New… Set the action to “Start a program” and browse to your sleep.bat script. Click OK.
Here’s your action:
If you want to prevent the computer from sleeping if programs are running or someone is using the computer, then use the following settings in the Conditions tab:
Click OK. You’re done with this part. If you want to test it out, you can add a new trigger that sets it in motion 1 minute from now.
Next, let’s make a Wake task. Click Action and Create Task… and name it Wake in the general tab.
Then, create a daily trigger with the time you want to wake your computer.
Next, go to the Actions tab and make an action to run your wake.bat script.
Now, go to the Conditions tab. Here, make sure that the “Wake the computer to run this task” option is checked.
Click OK. Now, your computer will wake and sleep at the scheduled times. Enjoy!