I have created scheduled tasks on both a Vista and Win7 machine which wake up the machine if it is currently in a sleep state. However, if the task takes longer than the power settings are configured on the machine, the machine will return to a sleep state. It looks like this utility might be a solution, but I was wondering if there were other options.

Does anyone know of a powershell command or other utility that will prevent my machine from going into a sleep state while a task is running?

4 Answers 4


The simplest way I have found to easily switch power modes to manage the machines ability to manage power is by defining Power Schemes. You just go into control panel and create any new power schemes or edit the existing existing predefined schemes. Setup a scheme for how you want the machine to behave normally where it does go to sleep when allowed. For example, on my Windows 7 machines I just edit the predefined "Balanced" power scheme for this. Then edit or create a scheme where the machine runs at full speed / power 100% of the time and is not allowed to sleep. Again, I just edit the existing "High Performance" power scheme and configure it that way. Then once these power schemes are defined you can easily script the mode the machine is running in using the POWERCFG.EXE command line utility.

Pop open a command line window and run:

powercfg -list

... when that runs, you should get a list of all of the machines defined power schemes along with the corresponding GUID value that you will need to note. Then to switch the machine from one power scheme to another, I have a simple batch file / script that I can run which passes the GUID for the scheme I want the machine to be running in. This way in my scheduled tasks and other tools, I can just call one of my scripts to keep the machine running without hibernating or at full speed. The batch file just uses powercfg.exe with the setactive switch to pick which power scheme I want. So this will look something like:

powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e

Just note that the last part is the GUID for your machine that you get by using the above list command.

  • 3
    +1, I don't know why this doesn't have more upvotes. To my mind it's the cleanest solution to the problem and it doesn't rely on buggy/undocumented behavior. Thanks for sharing.
    – Dominic P
    Feb 20, 2014 at 18:34

There should be a checkbox in the options for scheduling a task. I don't have Win 7 in front of me at the moment so I can't say exactly where, just that I've used it before.

  • I know there is a checkbox for waking up the machine to run a scheduled task. Are you saying there is one to prevent the machine from going to sleep during the scheduled task too?
    – Kevin
    Oct 21, 2009 at 21:04
  • I knew I forgot to check something when I went home... Last I checked, there is a box to prevent it from going to sleep while the task is running.
    – AnonJr
    Oct 23, 2009 at 18:16
  • There's no box to prevent it from going back to sleep, but the box wake the computer to run this task also prevents the computer from going to sleep Feb 5, 2012 at 2:53
  • The option to wake the computer does NOT prevent the computer from returning to sleep in the middle of task execution. That's what the question is all about.
    – kreemoweet
    Feb 5, 2012 at 4:19

There is a setting in Scheduled Tasks that you can check or uncheck which will cause a task or script to exit if it runs longer than the time specified by the checked setting. For example, if you have a task which wakes up your computer at 4 AM to do windows updates, virus scans, etc, the task will not finish if it takes longer than the time set for it at Scheduled-Tasks->Task.Name->Properties->Settings. If you have this time set for a shorter duration than the task needs, it may appear that the task failed to finish because the computer went into standby while the task was still running, but the real reason is that a longer time has to be set. Or the box can be unchecked so there is no time constraint at all.


In task scheduler go to properties - conditions tab - select 'Wake the computer to run this task'. In W7 this also triggers the computer to not go to hibernate if the task is running

edit- as commenters have pointed out, this bug may not be fixed. I haven't experienced it which is why I figured it was fixed, but there are reports that it wasn't fixed between vista and 7, which is what the OP indicates. Three is a thread over on Acronis with a script you can create and run with tasks that will stop the computer from hibernating. Additionally, there's a post on this website about inserting ping into your tasks to stop the computer from hibernating.

  • If this bug has been fixed in Win7, that's good to know, but it still occurs in Vista, which is one of the subjects of this question.
    – kreemoweet
    Feb 5, 2012 at 4:23
  • The Question author seems to be claiming that your assertion is not correct. Do you have a reference?
    – kreemoweet
    Feb 5, 2012 at 4:37
  • It works for me, but I'm on a desktop. Might just be my settings. this thread step 10 indicates that you must change some sleep return timeout settings per this method. Unfortunately, I can't find any documentation that W7 fixed this bug from vista. Feb 5, 2012 at 12:05
  • this post has a good workaround for the bug, if it hasn't been fixed. I can't find any documentation that it has been fixed even though I don't experience it. I'll leave my answer up for reference and update it with pertinent information Feb 5, 2012 at 12:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .