eshloraque

Windows 10 Battery saving mode

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by pluto41

Share this post


Link to post
Share on other sites

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 ;(

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites

Thanks a lot,

this does work as expected.

 

Share this post


Link to post
Share on other sites

You're wellcome.

 

Saludos

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