Jump to content

BatteryQueryEx - Minor addition to PsaltyDS's BatteryQuery UDF


Recommended Posts

Continuing "http://www.autoitscript.com/forum/index.php?showtopic=10993" 

WMI calls fail very badly if u are running a PC with AC Power, so i have been searchign for any api call to find out ac power supply status, then found GetSystemPowerStatus Function, worked hard on it to extract basic info using Autoit dllcall, then whoa, fool, there is already an UDF properly built by Masters..

i have put my extension as required - just a small piece of information - Battery Capacity When Fully Charged - its only an idea and may not work properly always, but yet. if someone finds it usefult, here it goes.

#Region Example 
#include <array.au3>
$batt = _BatteryQueryEx()
_ArrayDisplay($batt)
#EndRegion

#include-once
;======================================================
;    _BatteryQueryEx()
;    original author PsaltyDS http://www.autoitscript.com/forum/index.php?showtopic=10993&view=findpost&p=531988
;    Rajesh V R - addition of BatteryFullLifeTime
;    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>66%, 2=Low<33%, 4=Critical<5%,
;                      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)
;        $array[4]    = BatteryLife @ Full Capacity (Seconds of battery life if fully charged -1 if info not available Not applicable for AC Source)
;   @Link :         http://msdn.microsoft.com/en-us/library/aa373232(VS.85).aspx
;======================================================
Func _BatteryQueryEx()
    Local $SystemPower, $ret, $array[5]

    ; 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
    $array[4] = DllStructGetData($SystemPower, 6);    Sec Battery Capacity @ Full Charge

    ; free the struct
    $SystemPower = 0

    Return $array
EndFunc   ;==>_BatteryQueryEx
Edited by rajeshontheweb
Link to comment
Share on other sites

  • 4 years later...

Function is included in AutoIt v3.3.10+ as _WinAPI_GetSystemPowerStatus().

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
 Share

  • Recently Browsing   0 members

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