DWORD DisableDisplayPowerXP(bool bDisable)
{
DWORD dwRet = 0;
static const UINT nId = 100;
static UINT nOriginalValue = 0;
static BOOL bModify = FALSE;
if (bDisable)
{
if (!bModify)
{
POWER_POLICY policy = {0};
GetActivePwrScheme(&nOriginalValue);
if (!ReadPwrScheme(nOriginalValue, &policy))
{
dwRet = GetLastError();
goto _Exit;
}
//显示器
policy.user.VideoTimeoutAc = 0;
policy.user.VideoTimeoutDc = 0;
//硬盘
policy.user.SpindownTimeoutAc = 0;
policy.user.SpindownTimeoutDc = 0;
//休眠
policy.mach.DozeS4TimeoutAc=0;
policy.mach.DozeS4TimeoutDc=0;
//待机
policy.user.IdleTimeoutAc = 0;
policy.user.IdleTimeoutDc = 0;
if (!WritePwrScheme((PUINT)&nId, _T("FUCKPOWER"), _T("FUCKPOWER"), &policy))
{
dwRet = GetLastError();
goto _Exit;
}
if (!SetActivePwrScheme(nId, NULL, NULL))
{
dwRet = GetLastError();
DeletePwrScheme(nId);
goto _Exit;
}
bModify = TRUE;
}
}
else
{
if (bModify)
{
bModify = FALSE;
if (nOriginalValue != nId)
{
if (!SetActivePwrScheme(nOriginalValue, NULL, NULL))
{
dwRet = GetLastError();
}
DeletePwrScheme(nId);
}
}
}
_Exit:
return dwRet;
}