eshloraque Posted July 23, 2016 Posted July 23, 2016 Hey great community, You just helped me a lot. Thanks. How can I check, if the battery saving mode is enabled? This one which kicks in at 20% power left?
pluto41 Posted July 23, 2016 Posted July 23, 2016 (edited) ; This is how its be done with VBScript ; -------------------------------------- ; strComputer = "." ; Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") ; Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery",,48) ; For Each objItem in colItems ; Wscript.Echo objItem.EstimatedChargeRemaining&"%" ; Next ; Conversion to AutoIT script ; --------------------------- Local $sLevel = Battery_Level ( ) ConsoleWrite ( "Battery level: " & $sLevel & "%" & @CRLF ) Func Battery_Level ( ) Local $Obj_Item, $Col_Items, $ilevel = 0 Local $Obj_WMIService = ObjGet ( 'winmgmts:\\' & @ComputerName & '\root\cimv2' ) If ( IsObj ( $Obj_WMIService ) ) And ( Not @error ) Then $Col_Items = $Obj_WMIService.ExecQuery( 'Select * from Win32_Battery' ) For $Obj_Item In $Col_Items $ilevel = $Obj_Item.EstimatedChargeRemaining Next Else MsgBox ( 48, "Error", "WMI Object/Error :(" ) EndIf Return $ilevel EndFunc I don't have a laptop so i can't test this properly. When i run the code it says: "0%". But perhaps this example gives you some ideas to solve the problem. Edited July 23, 2016 by pluto41
eshloraque Posted July 24, 2016 Author Posted July 24, 2016 Nice idea ... reading the attribute Availability could have done the trick ... but it does not report (on Win 10) if it is in Power Save - Low Power Mode ... what a pitty ;(
Danyfirex Posted July 24, 2016 Posted July 24, 2016 Hello. You have to use GetSystemPowerStatus. Something like this should work. (I have not laptop to check) Global Const $tagSYSTEM_POWER_STATUS = 'byte ACLineStatus;byte BatteryFlag;byte BatteryLifePercent;byte SystemStatusFlag;' & _ 'int BatteryLifeTime;int BatteryFullLifeTime' ;~ ;SystemStatusFlag ;~ ;Note This flag was introduced in Windows 10. This flag was previously reserved, named Reserved1, and had a value of 0. Local $BatterySaverStatus = _GetBatterySaverStatus() MsgBox(0, "Info", "Battery Saver is : " & ($BatterySaverStatus ? "Enabled" : "Disabled")) Func _GetBatterySaverStatus() Local $tSYSTEM_POWER_STATUS = DllStructCreate($tagSYSTEM_POWER_STATUS) Local $aRet = DllCall('kernel32.dll', 'bool', 'GetSystemPowerStatus', 'struct*', $tSYSTEM_POWER_STATUS) If @error Or Not $aRet[0] Then Return SetError(1, @extended, 0) Return DllStructGetData($tSYSTEM_POWER_STATUS, 4) EndFunc ;==>_GetBatterySaverStatus Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
eshloraque Posted July 24, 2016 Author Posted July 24, 2016 Thanks a lot, this does work as expected.
Danyfirex Posted July 24, 2016 Posted July 24, 2016 You're wellcome. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
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