Prevent Sleep – How to Stop Sleep Mode in Scripts on Windows 7

command linecygwin;sleepwindows 7

Is there a way to prevent Windows from going into sleep mode while running a program on the command line or with cygwin? Ideally, I'm hoping for something that could be used like:

nosleep myscript.sh

Background

Sometimes I start up long-running jobs like a manual backup or large file transfers and I've found that Windows often goes to sleep before these finish. I'd like to be able to start up the command and prevent sleep mode while the command is running, but have it automatically work again once the command has completed.

Best Answer

You may use powercfg in a script to change the time the PC waits until it goes to sleep:

Never go to standby:

powercfg -change -standby-timeout-ac 0

Go to standby in 15 minutes:

powercfg -change -standby-timeout-ac 15
Related Question