rajeshontheweb Posted June 22, 2009 Share Posted June 22, 2009 (edited) 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. expandcollapse popup#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 June 22, 2009 by rajeshontheweb Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
sennabot Posted April 28, 2014 Share Posted April 28, 2014 thanks for rajesh and ejoc, this was so useful for me Link to comment Share on other sites More sharing options...
guinness Posted April 28, 2014 Share Posted April 28, 2014 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now