Akku Status von Notebook/Laptop anzeigen

    • VB.NET

    Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von markushettmann.

      Akku Status von Notebook/Laptop anzeigen

      VB.NET-Quellcode

      1. Private Structure SYSTEM_POWER_STATUS
      2. Public ACLineStatus As Byte
      3. Public BatteryFlag As Byte
      4. Public BatteryLifePercent As Byte
      5. Public Reserved1 As Byte
      6. Public BatteryLifeTime As Integer
      7. Public BatteryFullLifeTime As Integer
      8. End Structure
      9. Private Declare Function GetSystemPowerStatus Lib "kernel32" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
      10. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      11. Dim power_status As SYSTEM_POWER_STATUS
      12. If GetSystemPowerStatus(power_status) = 0 Then
      13. lblACStatus.Text = "Error"
      14. Else
      15. Select Case power_status.ACLineStatus
      16. Case 0
      17. lblACStatus.Text = "Battery"
      18. Case 1
      19. lblACStatus.Text = "On line"
      20. Case 255
      21. lblACStatus.Text = "Unknown"
      22. End Select
      23. Dim txt As String = ""
      24. If power_status.BatteryFlag And 1 Then txt &= ", High (> 66%)"
      25. If power_status.BatteryFlag And 2 Then txt &= ", Low (< 33%)"
      26. If power_status.BatteryFlag And 4 Then txt &= ", Critical (< 5%)"
      27. If power_status.BatteryFlag And 8 Then txt &= ", Charging"
      28. If power_status.BatteryFlag And 128 Then txt &= ", No system battery"
      29. If power_status.BatteryFlag = 255 Then txt &= ", Unknown"
      30. If txt.Length > 0 Then txt = txt.Substring(2)
      31. lblBatteryStatus.Text = txt
      32. End Sub
      33. End Class


      Fehler im Code gefixxt (von Chrisber)

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Chrisber“ ()