0

I'm writing a Windows service using WinAPIs and C++. One of the options is that I need to send the system into sleep after all users are logged out. The log-out command is started from the UI (which can notify my service), the problem is knowing how long it takes for all user accounts to be completely logged out before putting the system to sleep.

I first thought to introduce an artificial delay from the moment when the log-out command is issued and before entering the sleep mode, but in a situation when some user account was configured with a roaming profile, the log-out process may well exceed my delay.

So any suggestions how to know if all user accounts are logged out "for sure"?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    See http://stackoverflow.com/a/6273024/2786682 – Ivan Nov 17 '13 at 10:51
  • @IvanGrynko: That approach didn't really work for me. I tried it and his method returns 7 logged on users on my Windows 8 desktop when it's only 1. – c00000fd Nov 18 '13 at 02:39

1 Answers1

0

A better options is probably to periodically (every 3-5 minutes) check if there are any interactive sessions active. If not - bring the system to sleep.

The overhead of a service enumerating the interactive sessions every few minutes is so small that I don't think it's worth the effort to develop some form of advanced event handling system.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217