Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:



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.

share|improve this question
up vote 11 down vote accepted

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

Never go to standby:

powercfg -change -standby-timeout-ac 0

Go to standby in 15 minutes:

powercfg -change -standby-timeout-ac 15

share|improve this answer
Thanks. powercfg plus some bash magic are just what I needed. – Mr Fooz Jan 2 '10 at 16:39

Here's a bash script that I whipped up based on harrymc's response.


#   nosleep - prevent sleep and hibernation while running a command
#   nosleep COMMAND [ARG]...

# Make sure the power scheme gets restored, even if Ctrl-C happens
  powercfg -setactive $SCHEME_GUID
  powercfg -delete    $TMP_GUID
  return $?
trap cleanup SIGINT

# Disable sleep and hibernate timers
export SCHEME_GUID=`powercfg -getactivescheme | gawk '{ print $4 }'`
export TMP_GUID=`powercfg -duplicatescheme $SCHEME_GUID | gawk '{ print $4 }'`
if [[ -z $TMP_GUID ]]; then
    echo "ERROR: could not duplicate the current power scheme"
    exit 254
powercfg -setactive $TMP_GUID
powercfg -changename $TMP_GUID nosleep "temporary scheme for disabling sleep and hibernation"
powercfg -change -standby-timeout-ac 0
powercfg -change -hibernate-timeout-ac 0

# Run the command

powercfg -setactive $SCHEME_GUID
powercfg -delete    $TMP_GUID
share|improve this answer

Insomnia prevent your windows to go to sleep but it's not a command line tools, so your script with the harrymc commands are better solutions

share|improve this answer

You must log in to answer this question.

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