Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET]Check Battery Status

originally posted on dotnet-snippets.com

Description:

With this little class you can check the battery status of your notebook.

Code
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


If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
PHP & .NET Contributor.
The one way to take the result is
Code
MsgBox(BatteryStatus.GetStatus.BatteryLifePercent)
The structure should have an attribute applied (for stability):

Code
<StructLayout(LayoutKind.Sequential)> _
Structre ...

BatteryFlags should have the Flags() attribute applied, as it is a flags enum:

Code
<Flags()> _
Enum BatteryFlags as Byte
...
Lol gunna add this to my RAT.. check victoms Laptop battrey status.. why.. i dont know. but it will be cool
WTF 72 views and 3 replies lol

thanks for sharing
Nice work... Btw where do you get all these ideas of using the windows dlls and Api Calls for that good functions?
im glad you all like it.
PHP & .NET Contributor.
How come if i google any of "your" snippets i find them on dotnet-snippets.com?
Metal fans, attention!

Big collection thread for unknown/underground metal
bands here!

All sub-genres welcome!
He's just coping or he's the author of them @ dotnet-snippets.com ?
if you read the whole post you can tell that i posted it there and now here
PHP & .NET Contributor.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by HackooAug 29, 2018 12:49 AM 2 283 Aug 29, 2018 12:49 AM
Last Post: Sir-Teabag
[C#] by DotexeAug 5, 2017 04:23 PM 0 154 Aug 5, 2017 04:23 PM
Last Post: Dotexe
[.NET] by backtrackJun 22, 2015 11:05 AM 2 525 Jun 22, 2015 11:05 AM
Last Post: SIM-1456245