I'm writing a small program to save my laptop's battery, and I can now switch between power schemes using PowerSetActiveScheme
.
The next step is to control the battery saver in Windows 10. Though I can read the state of it using GetSystemPowerStatus
, I can't find a way to enable/disable it programmatically. Are there any functions in Windows API to do this?
Most probably you can do it Linux-way, by calling a system app named PowerCfg
through ShellExecuteEx()
:
powercfg /setdcvalueindex SCHEME_CURRENT SUB_ENERGYSAVER ESBATTTHRESHOLD 100
powercfg /setactive scheme_current
This means that the energy saver is activated even when the battery percentage equals 100%. SUB_ENERGYSAVER
and its sub-GUID ESBATTTHRESHOLD
are described here.
@hidefromkgb's answer is pretty much correct. The only missing part is that to disable Energy Saver and prevent it from turning it on, you need to do:
powercfg /setdcvalueindex SCHEME_CURRENT SUB_ENERGYSAVER ESBATTTHRESHOLD 0
powercfg /setdcvalueindex SCHEME_CURRENT SUB_ENERGYSAVER ESBRIGHTNESS 100
If you do that, and go back to the control panel Battery Saver section, you will see that the first checkbox is now disabled (although it still shows 20% but it is grayed out so it should be ok). Also the second checkbox (lower screen brightness) will be unchecked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With