Home » Questions » Computers [ Ask a new question ]

prevent sleep in scripts

prevent sleep in scripts

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:

Asked by: Guest | Views: 199
Total answers/comments: 2
Guest [Entry]

"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"
Guest [Entry]

"There is now such a nosleep command in Cygwin. Just install the nosleep package and run as

nosleep myscript.sh

Written by Andrew E. Schulman in 2011. See cygwin.com/ml/cygwin/2011-09/msg00151.html

The source on Launchpad. It uses SetThreadExecutionState() (like Insomnia already mentioned), doesn't create a separate power scheme.

Usage: nosleep [OPTION...] command [args]
Run a command while inhibiting computer sleep or hibernation.

-a, --awaymode Force away mode instead of sleep mode
-d, --display Keep the display on
-i, --ifacpower Following options only apply if AC power is on
-?, --help give this help list
--usage give a short usage message
-V, --version print program version

Report bugs to the Cygwin mailing list <cygwin@cygwin.com>.

Note that it prevents the system from automatically going to sleep on idle, not the system from going to sleep if requested by a user (like when closing a laptop lid)."