Mit dieser Klasse kann man den Status einer Laptop-Batterie abfragen.
Public Class BatteryStatus
Private Declare Auto Function GetSystemPowerStatus Lib "kernel32.dll" ( _
ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) _
As Integer
Public Structure SYSTEM_POWER_STATUS
Public ACLineStatus As ACLineStatus
Public BatteryFlag As BatteryFlag
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Integer
Public BatteryFullLifeTime As Integer
End Structure
Public Enum BatteryFlag As Byte
High = 1
Low = 2
Critical = 4
Charging = 8
NoSystemBattery = 128
Unknown = 255
End Enum
Public Enum ACLineStatus As Byte
Offline = 0
Online = 1
Unknown = 255
End Enum
Public Shared Function GetStatus() As SYSTEM_POWER_STATUS
Dim SPS As New SYSTEM_POWER_STATUS
GetSystemPowerStatus(SPS)
Return SPS
End Function
End Class
3 Kommentare zum Snippet