Sign in to follow this  
Followers 0
Gozzgug

BatteryQuery UDF doesn't work

2 posts in this topic

I downloaded this and the UDF doesn't seem to work. Does anyone know what might be wrong?

BatteryQuery

It would be nice to convert this UDF to use WMI but I wouldn't know where to start.

I am looking for a script to do a similar function as the link below but with WMI calls.

Power-Meter-Plus

Any sample code or a WMI version would be GREATLY appreciated.

Goz

Share this post


Link to post
Share on other sites



I downloaded this and the UDF doesn't seem to work. Does anyone know what might be wrong?

BatteryQuery

It would be nice to convert this UDF to use WMI but I wouldn't know where to start.

I am looking for a script to do a similar function as the link below but with WMI calls.

Power-Meter-Plus

Any sample code or a WMI version would be GREATLY appreciated.

Goz

I believe a WMI version was posted in that topic by SvenP a long time ago.

If you want to use the dll call, then some things needed to be updated because AutoIt's DLL functions have changed:

#include-once

;======================================================
;   _BatteryQuery()
;   Return information on the Battery
;   Sets @Error on error
;   Returns an array:
;       $array[0]   = ACPower(0=offline, 1=online, 255=unknown)
;       $array[1]   = BatteryFlag(1=High, 2=Low, 4=Critical,
;                     8=Charging 128=No Battery, 255=Unknown
;                     Use BitAnd to test, ie BitAnd($array[1],128)
;       $array[2]   = BatteryLife %(0-100, 255=unknown)
;       $array[3]   = Seconds left of charge, estimate(4294967295=unknown)
;======================================================
Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]

; Setup $array and $SystemPower
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
    If @error Then
        SetError(-1)
        Return $array
    EndIf

; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then;DllCall Failed
        SetError(-2)
        $SystemPower = 0
        Return $array
    EndIf

    If Not $ret[0] Then; GetSystemPowerStatus Failed
        SetError(-3)
        $SystemPower = 0
        Return $array
    EndIf

; Fill the array
    $array[0] = DllStructGetData($SystemPower, 1);  AC
    $array[1] = DllStructGetData($SystemPower, 2);  Battery Charge
    $array[2] = DllStructGetData($SystemPower, 3);  Battery Charge %
    $array[3] = DllStructGetData($SystemPower, 5);  Sec Battery Left

; free the struct
    $SystemPower = 0

    Return $array
EndFunc  ;==>_BatteryQuery

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0