This post is based on a Super User answer I wrote today.
Today I did some poking around in the Registry and discovered how power options are stored. The root of these settings is, predictably, HKLM\CurrentControlSet\Control\Power. All "IDs" relating to power management in the Registry are GUIDs, but my quick surveys show that the default ones are the same on all machines.
The User\PowerSchemes subkey of Power has an entry called ActivePowerScheme which contains the ID of the current power plan. The subkeys of PowerSchemes are, well, power schemes. 381b4222-f694-41f0-9685-ff5bb260df2e, for instance, represents Balanced (recommended).
The subkeys of the power scheme keys are categories as they appear in the advanced power options. These are defined in the PowerSettings subkey of Power. For instance, 0012ee47-9041-4b5d-9b77-535fba8b1442 is the one for Hard disk. The subkeys of those are the individual settings. 6738e2c4-e8a5-4a42-b16a-e040e769756e is the Turn off hard disk after setting. Those keys have a DefaultPowerSchemeValues subkey, which has a subkey for every standard power plan. Those keys have an AcSettingIndex and a DcSettingIndex entry which are exactly what you think. The units used vary from setting to setting. So, you can see that the default hard drive power-off timeout for the Balanced power plan is 1200 seconds (20 minutes) when plugged in and 600 seconds (10 minutes) on battery.
Now back to the User\PowerSchemes key. Since the user might not have ever changed the settings, there's no guarantee that the key will have both AC and DC setting entries, the setting subkey, or even the category subkey. If the desired value isn't there, the system checks the default value for the current power plan back in PowerSettings\DefaultPowerSchemeValues.
Note that none of this should be used by serious compiled applications. (For entertainment/scripting purposes only!) Developers of compiled applications should use the documented interface for power management. Call GetCurrentPowerPolicies, and - for the settings we looked at here - get the user part of the POWER_POLICY structure, then look at the SpindownTimeoutAc and SpindownTimeoutDc values.
No comments:
Post a Comment