irk B wrote:
Cheap method that may work:
Windows provides SetThreadExecutionState for situations like this.
Here's the article from the Platform SDK, just in case you didn't have it.
The SetThreadExecutionState function enables applications to inform the
system that it is in use, thereby preventing the system from entering
the sleeping power state while the application is running.
[in] Thread's execution requirements. This parameter can be one or more
of the following values. Flag Meaning
ES_SYSTEM_REQUIRED Informs the system that the thread is performing some
operation that is not normally detected as activity by the system.
ES_DISPLAY_REQUIRED Informs the system that the thread is performing
some operation that is not normally detected as display activity by the
ES_USER_PRESENT Informs the system that a user is present. If a user is
present, the system will use the power policy settings set by the user.
Otherwise, the system does not wake the display device and will return
to the sleeping state as soon as possible.
ES_CONTINUOUS Informs the system that the state being set should remain
in effect until the next call that uses ES_CONTINUOUS and one of the
other state flags is cleared.
If the function succeeds, the return value is the previous thread
If the function fails, the return value is NULL.
Activities that are automatically detected include local keyboard or
mouse input, server activity, and changing window focus. Activities that
are not automatically detected include disk or CPU activity and video
Calling SetThreadExecutionState with ES_SYSTEM_REQUIRED prevents the
system from putting the computer in the sleeping state by resetting the
system idle timer. Calling SetThreadExecutionState with
ES_DISPLAY_REQUIRED prevents the system from turning off the display by
resetting the display idle timer. Calling SetThreadExecutionState
without ES_CONTINUOUS simply resets the idle timer; to keep the display
or system in the working state, the thread must call
To run properly on a power-managed computer, applications such as fax
servers, answering machines, backup agents, and network management
applications must use ES_SYSTEM_REQUIRED | ES_CONTINUOUS when they
process events. Multimedia applications, such as video players and
presentation applications, must use ES_DISPLAY_REQUIRED when they
display video for long periods of time without user input. Applications
such as word processors, spreadsheets, browsers, and games do not need
to call SetThreadExecutionState.
The SetThreadExecutionState function cannot be used to prevent the user
from putting the computer in standby mode. To prevent the user from
putting the computer in standby mode, the application must deny the
This function does not always stop the screen saver from executing when
the computer is in use. As an alternative, set a timer and periodically
call the SystemParametersInfo function to query and reset the screen
saver time-out value. (Use the user's default settings in case your