I want prevent system from going to sleep/hibernate from a windows service.
I am calling SetThreadExecutionState function to do that.
But it seems to have no effec
Calling SetThreadExecutionState without ES_CONTINUOUS simply resets the idle timer; to keep the display or system in the working state, the thread must call SetThreadExecutionState periodically.
(source)
You need to call this function every now and then. It's not a fire-and-forget.