0

I have used the template provided Here, to create a windows service. I would like to use this service to reset the system idle timer to avoid the OS going to sleep mode.

SetThreadExecutionState, seems the be the right way of doing so. However, it appears that this method, does not work when the program is running as a service. I have even tried sending an event with keybd_event function, but it appears that there are some security measures in place (see question No. 12747430), to filter out mouse/keyboard events for non-desktop applications ( Even though 'Allow service to interact with desktop' option, is checked for the service).

So here's the question: How can i reset the system idle timer through a windows service? (should not be dependent on user's desktop and should work on login screen as well)

PS: the OS is windows 7 x64

Thanks in advance

5
  • Why? Typically, services don't care when the PC goes to sleep. They're doing background tasks. The big exception are services on servers, but servers usually don't have sleep configured in power management.
    – MSalters
    Jun 6, 2013 at 12:00
  • Google "session 0 isolation" to find out why this cannot work. You'll need a little applet that runs in the desktop session. Jun 6, 2013 at 12:29
  • @MSalters : there could be plenty of reason for doing so. my reason is rather specific. but i could give you an example close enough: assume you have a fax server running as a service. the OS is set to go to sleep mode after 1 minute to consume as little power as possible. the modem has WOR capability to wake the pc up so the the service could get the fax. however, you want to ensure the pc would not go to sleep mode while reviving the fax...
    – J_Banner
    Jun 6, 2013 at 12:51
  • @HansPassant Thank you for the info. but i still believe there should be some way for doing so. at the very least sending some keyboard/mouse events. RealVNC comes to mind as an example of an application running as a service, and yet capable of sending keyboard/mouse events even on login screen.
    – J_Banner
    Jun 6, 2013 at 12:55
  • @J_Banner: In that situation, the modem driver is responsible to keep the OS awake. If it does so, Windows will understand that the screen can go to sleep, but not the CPU. Your idea would fail to power down the screen.
    – MSalters
    Jun 6, 2013 at 14:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.