I need to allow WakeTimers (computer wake up from sleep/hibernation) for all power plans set on plugged in to Enabled.
I tried Win32_PowerSetting but it only works on english version of Windows.
I need to use .NET 2.0
Thanks for responses !
I suspect you can do this using API calls to powrprof.dll, as well as WMI, but I haven't had the time to figure that approach out.
This setting appears to be simply a boolean registry key that is located according to your current power plan:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\(Current Power Scheme GUID)\(Sleep Category GUID)\(Enable AC or DC Wake Timers GUID) = 0 or 1
Rather than manipulating the registry directly a cleaner approach would be to enable these settings using powercfg.exe.
For AC power:
powercfg.exe -SETACVALUEINDEX SCHEME_CURRENT SUB_SLEEP bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d 1
For Batteries:
powercfg.exe -SETDCVALUEINDEX SCHEME_CURRENT SUB_SLEEP bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d 1
EDIT:
This enables wake timers on my system when running on AC power using High Performance power scheme (purely as a proof of concept):
[DllImport("powrprof.dll", EntryPoint = "PowerWriteACValueIndex", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint PowerWriteACValueIndex(IntPtr RootPowerKey, ref Guid SchemeGuid, ref Guid SubGroupOfPowerSettingsGuid, ref Guid PowerSettingGuid, uint AcValueIndex);
public static void EnableWakeTimers()
{
Guid Root = new Guid("8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"); // High Performance GUID
Guid Sleep = new Guid("238c9fa8-0aad-41ed-83f4-97be242c8f20"); // Sleep Subcategory GUID
Guid WakeTimers = new Guid("bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d"); // Wake Timers GUID
PowerWriteACValueIndex(IntPtr.Zero, ref Root, ref Sleep, ref WakeTimers, 1);
}
This reference is your friend: http://msdn.microsoft.com/en-us/library/aa373163%28v=vs.85%29.aspx