I have found a two work arounds.
Originally Posted by ucdchan
On Vista and later, some Googling reveals that there should be a registry setting that controls this. I haven't tried the settings because I haven't been encountering the problem on Vista or later. But the relevant posts can be found by Googling for the following keywords:
How to change the Return to Sleep Timeout for a Unattended Wake Up in Vista
The post I found that details these registry keys is here:
I cannot find those registry keys on Windows XP, yet XP is where I'm encountering the problem. (Yes, I know XP is old but we're still shipping software for it and so I still have to test it.) So instead, I am implementing the solution described in this post:
This solution involves writing another keep-awake program that you use as part of your automation. I happened to write the program in VB because that was the example given at the link above, but you could do it in C as well. The program doesn't have to do anything to keep the system awake... it doesn't need to move the mouse or press keys or anything. It merely sits there idle and does nothing, after executing this single code line:
' parameter is the hexadecimal sum of the ES_CONTINUOUS and the ES_SYSTEM_REQUIRED flags
As long as that program is left running (even minimized) with its thread execution state set that way, then the system theoretically will not go into the second unexpected "automatic" sleep if the system is left idle after Sleeper is done. Interestingly, in my tests, this does NOT seem to interfere with deliberate sleeps such as those Sleeper.exe would induce, and it does not interfere with deliberate sleeps from pressing the Sleep key on the computer. It only seems to fix the "wake unattended re-sleep" issue that we're hitting here in this thread. Convenient!
You could theoretically include that line (or its equivalent) in your test automation code itself instead of writing another program.