How to get notified when going in and out of connected standby from a Windows Service?

Always on Connected Standby (AOAC) was introduced in Windows 8.  Here is the definition as described on MSDN:

"Starting with Windows 8 and Windows 8.1, connected standby is a new low-power state that features extremely low power consumption while maintaining Internet connectivity. For a PC that implements the connected standby power model, the connected standby power state serves as the primary off mode for the PC—similar to the off mode that a smartphone enters when the user presses the power button. The Windows UI exposes the connected standby power state to the end user as the system "sleep" state."

When going into connected standby Windows Store Applications are suspended as well as Windows Desktop Applications (via the Desktop Activity Moderator through Job Objects).  Windows Services which are located in session 0 are not suspended but instead are throttled.  Windows Desktop Applications can be notified when going into connected standby by registering for a notification.  See the following for more information:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh848040(v=vs.85).aspx

Unfortunately this doesn't apply to Windows Services which are located in session 0 and have no GUI (you can send a message box via WTSSendMessage) and thus have no display.

Connected Standby is synonymous with the display where on an AOAC capable system the display is turned off when going in to connected standby and turned on when leaving this state.

The solution for a service is to monitor on/off notifications for the display.  What you need to do from your service is the following:

  1. Determine if the system is AOAC capable by calling CallNtPowerInformation and looking at the AoAc value of the SYSTEM_POWER_CAPABILITIES struct).
  2. To get monitor on/off notifications you can call:

RegisterPowerSettingNotification
(https://msdn.microsoft.com/en-us/library/windows/desktop/aa373196(v=vs.85).aspx)

And use the GUID_MONITOR_POWER_ON power setting GUID.

Follow us on Twitter, www.twitter.com/WindowsSDK

Comments

  • Anonymous
    June 15, 2015
    Hi, My quick question is how can we write a Universal Windows App to determine if the system is AOAC capable?  I can declare SYSTEM_POWER_CAPABILITIES variables, but neither CallNtPowerInformation() nor GetPwrCapabilities() can be called in UWA for Windows 10 -- I could not figure out what (SDK) references need to be added. Thanks!

  • Anonymous
    June 15, 2015
    What are you trying to accomplish?  Windows should handle all your power management needs which is different from a Windows Service which is a legacy application. thanks

  • Anonymous
    June 15, 2015
    Hi Frank, I was asked to write a proof-of-concept Universal Windows app for Windows 10 (desktop/laptop/2in1) to behave differently based on whether the system is AOAC capable, and therefore filling the AoAc entry in SYSTEM_POWER_CAPABILITIES (through GetPwrCapabilities()) is what I can think of.  AOAC can be enabled/disabled through BIOS and thus I think the app needs to actually test it. If there are MSDN/blog articles on this being legacy and another sample code or snippet is available to achieve something similar, that will be great so I can point to my management on the new direction for Windows 10 and implement what they need. Thanks Frank.

  • Anonymous
    June 16, 2015
    Take a look at this thread: social.msdn.microsoft.com/.../how-i-can-put-windows-8-into-connected-standby-mode

  • Anonymous
    June 16, 2015
    Thanks Frank!  Will take some time to study......