我有一个需要在设置值后获取睡眠的应用程序,我现在有代码可以从电源计划中获取休眠值设置,现在我的挑战是在之后从Sleep中获取设置值。
如果我想在以后睡个好觉怎么办?我尝试将“ 29f6c1db-86da-48c5-9fdb-f2b67b1f44da” GUID用作PowerSettingsGuid来获取Sleep After值,但它不起作用,并且始终会获取Hibernate值。
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
下面是我在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.";
}