Created
September 13, 2017 13:19
-
-
Save janhajk/87bb61b665f183fccbcfddbc19f4a9c3 to your computer and use it in GitHub Desktop.
VBA get Battery Life Percentage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Type SYSTEM_POWER_STATUS | |
ACLineStatus As Byte | |
BatteryFlag As Byte | |
BatteryLifePercent As Byte | |
Reserved1 As Byte | |
BatteryLifeTime As Long | |
BatteryFullLifeTime As Long | |
End Type | |
Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long | |
Private Sub GetBatteryStatus() | |
Dim SPS As SYSTEM_POWER_STATUS | |
GetSystemPowerStatus SPS | |
Dim i% | |
i = SPS.BatteryLifePercent | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment