How to get value of advanced power settings for sleep after

0

I have an application the needs to get the sleep after setting value, I have codes now that gets the Hibernate value setting from power plan and now my challenge is to get the setting values from Sleep after.

enter image description here

What if I want to get the SLEEP AFTER? I try to use the "29f6c1db-86da-48c5-9fdb-f2b67b1f44da" GUID as PowerSettingsGuid to get the Sleep After value but it doesn't work and it always get the Hibernate values.

Subgroup GUID: 238c9fa8-0aad-41ed-83f4-97be242c8f20  (Sleep)
GUID Alias: SUB_SLEEP
Power Setting GUID: 29f6c1db-86da-48c5-9fdb-f2b67b1f44da  (Sleep after)
  GUID Alias: STANDBYIDLE
  Minimum Possible Setting: 0x00000000
  Maximum Possible Setting: 0xffffffff
  Possible Settings increment: 0x00000001
  Possible Settings units: Seconds
Current AC Power Setting Index: 0x00000708
Current DC Power Setting Index: 0x00000384

Power plan group

Below are the codes I copied on the How to get the value of advanced power settings post

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");
private static Guid GUID_STANDBYIDLE = new Guid("29f6c1db-86da-48c5-9fdb-f2b67b1f44da");

[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);

private void Get_SLEEP_AFTER_SETTINGS()
{
    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_STANDBYIDLE, ref type, ref value, ref valueSize);

    var message = $"Sleep setting is {value} seconds.";
}
c#
xamarin.forms
uwp
uwp-xaml
xamarin.uwp
asked on Stack Overflow Dec 1, 2018 by parpar • edited Dec 1, 2018 by C1sc0

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0