How can I prevent Windows from going to sleep during a scheduled task?

07
2013-09
  • Kevin

    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?

  • Answers
  • AnonJr

    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.

  • Smoove

    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.

  • Raystafarian

    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.

  • dmarietta

    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.


  • Related Question

    Windows doesn't wake up from sleep reliably when bluetooth is on
  • mika

    This issue has bugged me on multiple laptops for at least three years now, and I was wondering if anyone had similar experiences.

    The problem is that waking up from sleep results in a hang or BSOD, but only if bluetooth is enabled. This does not happen every time, but often enough that you have to be careful before using sleep mode at all.

    I think the most probable cause is the Windows driver (BTHUSB.SYS) for the particular bluetooth adapters i'm using, so I must specify the systems a little more. In both machines there has been BTHUSB errors in the Windows event log, but even these don't show up always.

    Apple MacBook (first generation)

    • Intel 945GM chipset (for Core Duo, not Core Duo 2)
    • "Built-in Bluetooth 2.0 + Enhanced Data Rate (EDR)"
    • Windows XP, Microsoft Bluetooth Driver (BTHUSB.SYS)
    • wakeup never crashes in MacOS, only in Windows
    • I don't know how you disable bluetooth in BIOS, so haven't tested without
    • sometimes just bluetooth goes down but Windows stays up

    Dell Latitude D380

    • Intel GM965 chipset
    • Dell Wireless 360 Bluetooth Module
    • Vista x64, Windows 7 x64, Microsoft Bluetooth Driver (BTHUSB.SYS)
    • wake-up from sleep works reliably if I disable bluetooth in BIOS
    • No error messages in event log (Windows 7)

    I don't expect that this can be solved, but I'd like to know what machines to avoid in the future. It was really a surprise that the Dell had the exact same problem as the older MacBook.


  • Related Answers
  • 8088

    Sleep problems occur again and again on this forum.
    This is a retake of my answer for thread 23820.

    Ideas for resolving not coming out of sleep:

    1. Look in your BIOS for the suspend ACPI options and try to switch modes among "S1 and S3", "S1", "S3" etc.
    2. Ensure "Allow this device to wake computer" is checked in in "Device Manager/$device$/ Properties/Power Management", where $device$ stands for keyboard and mouse.
    3. Turn off Hybrid sleep, see explanation here (for vista, but is the same)
    4. The hibernation file is sometimes disabled by disk cleaning, to restore do in cmd run as administrator "powercfg -h on".

    Note: Any of the above manipulation that doesn't help should be undone.
    Item 1 was the one that worked the last time this question was asked.

    In Windows 7 one can use the following command to troubleshoot sleep problems and return a detailed report:

    powercfg -ENERGY

    image

  • mika

    I was wrong.

    The problem with Dell Latitude D380 was a broken DDR2 SO-DIMM module, and had nothing to do with bluetooth.

    Replacing the memory fixed the issue. But I figured this out only after the machine started to give memory errors during the boot process.