我需要允许WakeTimers(计算机从睡眠/休眠状态唤醒)将插入的所有电源计划设置为已启用。
我尝试过Win32_PowerSetting,但它只适用于英文版的Windows。
我需要使用.NET 2.0
感谢您的回复!
答案 0 :(得分:4)
我怀疑你可以使用对powrprof.dll以及WMI的API调用来做到这一点,但我还没有时间去解决这个问题。
此设置似乎只是一个布尔注册表项,根据您当前的电源计划定位:
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Power \ User \ PowerSchemes \(当前电源方案GUID)\(睡眠类别GUID)\(启用AC或DC唤醒定时器GUID)= 0或1
不是直接操作注册表,而是使用powercfg.exe启用这些设置。
对于交流电源:
powercfg.exe -SETACVALUEINDEX SCHEME_CURRENT SUB_SLEEP bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d 1
对于电池:
powercfg.exe -SETDCVALUEINDEX SCHEME_CURRENT SUB_SLEEP bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d 1
编辑:
使用高性能电源方案(纯粹作为概念验证),在使用交流电源运行时,可在系统上启用唤醒定时器:
[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);
}
此引用是您的朋友:http://msdn.microsoft.com/en-us/library/aa373163%28v=vs.85%29.aspx
答案 1 :(得分:1)
您似乎可以使用WMI更改设置。
http://www.daniweb.com/software-development/csharp/threads/272577
Microsoft有一个WMI代码创建器可以帮助您:
https://www.microsoft.com/download/en/confirmation.aspx?displayLang=en&id=8572
您需要在“root \ CIMV2 \ power”下搜索电源管理内容。
答案 2 :(得分:1)
我写了这个powershell脚本来启用或禁用所有当前电源方案的唤醒定时器。在第二行" POWERCFG -setacvalueindex $ xAll $ xSubGuid $ zz 1" - 1表示启用。只需将其更改为0即可禁用。
CLS
#Capture Current Active Power Scheme
$orgScheme = POWERCFG -GETACTIVESCHEME
$yOrg = $orgScheme -split "\s+"
$xOrg = $yOrg[3]
Write-host Original Scheme = $xOrg
Echo __________________________________
Echo " "
$allScheme = POWERCFG /L
#Echo $allScheme
foreach ($line in $allScheme)
{
if ($line.Length -gt 40)
{
if ($line.substring(0,5) -eq "Power")
{
$yAll = $line -split "\s+"
$xAll = $yAll[3]
write-host $xAll
Powercfg -S $xAll
$pScheme = POWERCFG /Q
foreach ($line in $pScheme)
{
$yy = $line -split "\s+"
$xx = $yy[5]+$yy[6]+$yy[7]+$yy[8]
$zz = $yy[4]
$xSubGroup = $yy[1]
If($xSubGroup -eq "SubGroup")
{
$xSubGuid = $yy[3]
}
If($xx -eq "(allowwaketimers)")
{
write-host Power Scheme Guid = $xAll
write-host Subgroup Guid = $xSubGuid
write-host WakeUp Guid = $zz
Write-host POWERCFG -setacvalueindex $x $xSubGuid $zz 1
Echo " "
break
}
}
POWERCFG -setacvalueindex $xAll $xSubGuid $zz 1
}
}
}
Powercfg -S $xOrg
享受。
答案 3 :(得分:0)
来自https://adameyob.com/2015/02/how-to-enable-wake-timers/#comment-17
powercfg /SETACINDEXVALUE SCHEME_BALANCED SUB_SLEEP RTCWake 1
powercfg /SETACINDEXVALUE SCHEME_MIN SUB_SLEEP RTCWake 1
powercfg /SETACINDEXVALUE SCHEME_MAX SUB_SLEEP RTCWake 1
或者来自http://adameyob.com/2015/02/how-to-enable-wake-timers/#comment-31
FOR /f “tokens=1,2,3,4” %%I IN (‘powercfg.exe /getactivescheme’) DO ( SET GUID=%%L )
powercfg /setacvalueindex %GUID% SUB_SLEEP RTCWAKE 1