Jump to content

Recommended Posts

Posted

Something like this maybe?

$structSystemPowerStatus = DllStructCreate("byte ACLineStatus; byte BatteryFlag; byte BatteryLifePercent; byte Reserved1; dword BatteryLifeTime; dword BatteryFullLifeTime")
$ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($structSystemPowerStatus))
If @error Then Exit
If $ret <> 0 Then
    $nOnBattery   = DllStructGetData($structSystemPowerStatus,  "ACLineStatus")
    $nBatteryLife = DllStructGetData($structSystemPowerStatus,  "BatteryLifePercent")
    If $nOnBattery == 0 Then
        MsgBox(48, @ScriptName, "Running on battery. Percentage = " & $nBatteryLife)
    Else
        MsgBox(48, @ScriptName, "Running on AC-power")
    EndIf
EndIf
Posted

Something like this maybe?

$structSystemPowerStatus = DllStructCreate("byte ACLineStatus; byte BatteryFlag; byte BatteryLifePercent; byte Reserved1; dword BatteryLifeTime; dword BatteryFullLifeTime")
$ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($structSystemPowerStatus))
If @error Then Exit
If $ret <> 0 Then
    $nOnBattery   = DllStructGetData($structSystemPowerStatus,  "ACLineStatus")
    $nBatteryLife = DllStructGetData($structSystemPowerStatus,  "BatteryLifePercent")
    If $nOnBattery == 0 Then
        MsgBox(48, @ScriptName, "Running on battery. Percentage = " & $nBatteryLife)
    Else
        MsgBox(48, @ScriptName, "Running on AC-power")
    EndIf
EndIf
thanks~~~
  • 3 months later...
Posted

I was also looking for a way to make a power meter. I didn't find anything on the forums but stumbled on this on my own. I'm posting this on the posts that were talking about power meters.

This works on my Compaq running XP. It will import even it the window is hidden. I do have the icon set to always show in the taskbar. $power1 imports the words Batteries or AC Power and $power2 imports the battery life in percent.

$power1 = ControlGetText("Power Meter", "", "Static6")
 $power2 = ControlGetText("Power Meter", "", "Static8")
 msgbox (0,"", $power1 & "  " & $power2)
  • 3 months later...
Posted

Something like this maybe?

$structSystemPowerStatus = DllStructCreate("byte ACLineStatus; byte BatteryFlag; byte BatteryLifePercent; byte Reserved1; dword BatteryLifeTime; dword BatteryFullLifeTime")
$ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($structSystemPowerStatus))
If @error Then Exit
If $ret <> 0 Then
    $nOnBattery   = DllStructGetData($structSystemPowerStatus,  "ACLineStatus")
    $nBatteryLife = DllStructGetData($structSystemPowerStatus,  "BatteryLifePercent")
    If $nOnBattery == 0 Then
        MsgBox(48, @ScriptName, "Running on battery. Percentage = " & $nBatteryLife)
    Else
        MsgBox(48, @ScriptName, "Running on AC-power")
    EndIf
EndIf

Awsome! Just what I needed to complete my project! Thanks for posting this :)

  • 5 years later...
Posted
I changed it a bit, to make it comfortable for German Users:
$structSystemPowerStatus = DllStructCreate("byte ACLineStatus; byte BatteryFlag; byte BatteryLifePercent; byte Reserved1; dword BatteryLifeTime; dword BatteryFullLifeTime")
$x = 0
$p = 100
    While 1
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($structSystemPowerStatus))
    $nOnBattery   = DllStructGetData($structSystemPowerStatus,  "ACLineStatus")
    $nBatteryLife = DllStructGetData($structSystemPowerStatus,  "BatteryLifePercent")
    If $nBatteryLife < $p -5 Then
         MsgBox(48, "Batterie Status", "Der Akku ist nur noch zu "&$nBatteryLife&"% gefüllt!")
         $p = $nBatteryLife
    EndIf
    If $nOnBattery == 0 Then
        If $x = 1 Or $x = 0  Then
        MsgBox(48, "Nicht angeschlossen!", "Der Computer ist nicht angeschlossen, und läuft über den Akku. ("&$nBatteryLife&"%)")
        $x = 2
        EndIf
    Else
        If $x = 2 Or $x = 0 Then
        MsgBox(48, "Angeschlossen!", "Der Computer ist angeschlossen. ("&$nBatteryLife&"%)")
        $x = 1
        EndIf
    EndIf
    WEnd

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...