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

I have a computer (Dell Optiplex 170L, Windows XP) on which I'm testing out wake-on-lan functions. I have a script which wakes it up with the linux wakeonlan program successfully and then performs a ping. However, a little over 100 seconds after wakeup, it falls asleep again, interrupting or preventing what I wanted to wake it up for.

share|improve this question

I have noticed the same behaviour with a Windows7 laptop. Seems if a laptop is woken up using WoL, then Windows treats it differently. If there is no input to the machine within 2 minutes then Windows puts it back to sleep.

The solution is to tell Windows immediately after waking the machine that it shouldnt transition the machine to a low power state.

SetThreadExecutionState is the function that you need to call to prevent windows from transitioning it to low power mode. Depending on the flags you call it with, the effect varies.

You basically have to call


when Windows starts and then call


once your work is done.

ES_SYSTEM_REQUIRED implies to Windows that the system needs to be awake. ES_CONTINUOUS says that the state the machine has been set to, ie always stay awake, needs to remain till it has been otherwise changed by calling the same function with a diff parameter. Once your work is done, you make the second call. This is called with only the ES_CONTINUOUS. By not specifying ES_SYSTEM_REQUIRED, you are resetting the state to the default, ie allow Windows to manage the power state. And because of ES_CONTINUOUS, it will remain in this state till otherwise changed.

Btw, making the first call will only prevent Windows from managing power. If you have any other software that manages power, it will still transition the machine.

I know, this answer comes after many months of the original question, but am posting hoping that it helps the next guy who comes along.

share|improve this answer
That's good for a programmer, but I wasn't expecting to have to run custom software on the clients. – Justin Love Jul 6 '10 at 12:04
Windows has to do it for laptops. They might be on battery power when they are accidentally woken up by some random access. The newers versions not just support WoL, but also support waking the machine if someone makes a request for it on the lan. So, accidental wake ups are common. And its not really custom software. consider a part of the script that you are running for doing your work. I am assuming there must a WMI equivalent for the same that you can easily call from your script. – Amith George Jul 6 '10 at 18:56

I found this site which has software called StayAwake that prevents this behavior of falling asleep based on inactivity after WOL. Unfortunately, it prevents the computer from falling asleep altogether, overriding power options. However, I was able to schedule a task that explicitly tells the computer to sleep on the hour throughout the day, and Wake-On-Lan will still wake it up just the same, at least theoretically. I still have some problems with WOL as you'll see in the questions I asked, but it may be hardware related.

share|improve this answer

You must log in to answer this question.

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