public class Power
{
private const string POWER_TIMEOUT = @"System\CurrentControlSet\Control\Power\Timeouts";
private const string POWER_STATE_SUSPEND = @"System\CurrentControlSet\Control\Power\State\Suspend";
[DllImport("CoreDll")]
public static extern void SystemIdleTimerReset();
public static int PowerOffTime
{
set
{
RegistryKey rktimeout = Registry.LocalMachine.OpenSubKey(POWER_TIMEOUT, true);
if (rktimeout != null)
{
rktimeout.SetValue("ACSuspendTimeout", value, RegistryValueKind.DWord);
rktimeout.SetValue("BattSuspendTimeout", value, RegistryValueKind.DWord);
rktimeout.Close();
}
RegistryKey rksuspend = Registry.LocalMachine.OpenSubKey(POWER_STATE_SUSPEND, true);
if (rksuspend != null)
{
rksuspend.SetValue("Default", value == 0 ? 0 : 3, RegistryValueKind.DWord);
rksuspend.SetValue("Flags", value == 0 ? 0 : 209152, RegistryValueKind.DWord);
rksuspend.Close();
}
}
}
}
留言