What is the recommended approach for checking low battery events in Windows?

Rohan Pande 375 Reputation points
2024-05-29T06:22:42.56+00:00

Hi,

I am developing an application and need to register for a low-battery event in Windows. I have reviewed the PowerSettingGUIDs documentation and found a value named GUID_POWER_SAVING_STATUS.

Reference: https://learn.microsoft.com/en-us/windows/win32/power/power-setting-guids

However, this value is also set to true when the user manually turns on battery saver. What is the recommended approach for checking low battery events?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,473 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,346 Reputation points Microsoft Vendor
    2024-05-29T07:38:00.92+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You could try to use GetSystemPowerStatus function to retrieve the current power status of the computer. In particular, the application should check the BatteryFlag, BatteryLifeTime, and BatteryLifePercent members of the SYSTEM_POWER_STATUS structure for any changes. PBT_APMPOWERSTATUSCHANGE eventcan occur when battery life drops to less than 5 minutes, or when the percentage of battery life drops below 10 percent, or if the battery life changes by 3 percent.

    For more details you could refer to the Doc: System Power Status Events

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful