Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);

when Windows starts and then call

SetThreadExecutionState(ES_CONTINUOUS);

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.