You can get power advanced setting values including Hibernate After and Sleep After using Windows API, Registry, powercfg, and WMI.
The most important common information for all solutions is some GUID values:
- GUID of Active Plan (You should first find it.)
- GUID of Sleep Sub Group :
238c9fa8-0aad-41ed-83f4-97be242c8f20
- GUID of Hibernate After Setting:
9d7815a6-7ee4-497e-8888-515a05f02364
- GUID of Sleep After Setting:
29f6c1db-86da-48c5-9fdb-f2b67b1f44da
After you found the value, usually the value is hexadecimal and shows the seconds.
Using Windows API
You can use PowerGetActiveScheme
function to get the active power plan, then you can use PowerReadACValue
to get the value which you need.
To do so, first declare:
private static Guid GUID_SLEEP_SUBGROUP =
new Guid("238c9fa8-0aad-41ed-83f4-97be242c8f20");
private static Guid GUID_HIBERNATEIDLE =
new Guid("9d7815a6-7ee4-497e-8888-515a05f02364");
[DllImport("powrprof.dll")]
static extern uint PowerGetActiveScheme(
IntPtr UserRootPowerKey,
ref IntPtr ActivePolicyGuid);
[DllImport("powrprof.dll")]
static extern uint PowerReadACValue(
IntPtr RootPowerKey,
ref Guid SchemeGuid,
ref Guid SubGroupOfPowerSettingGuid,
ref Guid PowerSettingGuid,
ref int Type,
ref int Buffer,
ref uint BufferSize);
Then find the value this way:
var activePolicyGuidPTR = IntPtr.Zero;
PowerGetActiveScheme(IntPtr.Zero, ref activePolicyGuidPTR);
var activePolicyGuid = Marshal.PtrToStructure<Guid>(activePolicyGuidPTR);
var type = 0;
var value = 0;
var valueSize = 4u;
PowerReadACValue(IntPtr.Zero, ref activePolicyGuid,
ref GUID_SLEEP_SUBGROUP, ref GUID_HIBERNATEIDLE,
ref type, ref value, ref valueSize);
MessageBox.Show($"Hibernate after {value} seconds.");
Note
You can also find example of using Registry or using WMI in a blog post.