1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214:
| unit PowrProf;
interface
uses Types, Windows;
const PO_THROTTLE_NONE = 0; PO_THROTTLE_CONSTANT = 1; PO_THROTTLE_DEGRADE = 2; PO_THROTTLE_ADAPTIVE = 3; PO_THROTTLE_MAXIMUM = 4; NUM_DISCHARGE_POLICIES = 4; DISCHARGE_POLICY_CRITICAL = 0; DISCHARGE_POLICY_LOW = 1;
type NTSTATUS = cardinal; POWER_ACTION = (PowerActionNone = 0, PowerActionReserved, PowerActionSleep, PowerActionHibernate, PowerActionShutdown, PowerActionShutdownReset, PowerActionShutdownOff, PowerActionWarmEject );
SYSTEM_POWER_STATE = (PowerSystemUnspecified = 0, PowerSystemWorking = 1, PowerSystemSleeping1 = 2, PowerSystemSleeping2 = 3, PowerSystemSleeping3 = 4, PowerSystemHibernate = 5, PowerSystemShutdown = 6, PowerSystemMaximum = 7 );
POWER_INFORMATION_LEVEL = (SystemPowerPolicyAc, SystemPowerPolicyDc, VerifySystemPolicyAc, VerifySystemPolicyDc, SystemPowerCapabilities, SystemBatteryState, SystemPowerStateHandler, ProcessorStateHandler, SystemPowerPolicyCurrent, AdministratorPowerPolicy, SystemReserveHiberFile, ProcessorInformation, SystemPowerInformation, ProcessorStateHandler2, LastWakeTime, LastSleepTime, SystemExecutionState, SystemPowerStateNotifyHandler, ProcessorPowerPolicyAc, ProcessorPowerPolicyDc, VerifyProcessorPowerPolicyAc, VerifyProcessorPowerPolicyDc, ProcessorPowerPolicyCurrent, SystemPowerStateLogging, SystemPowerLoggingEntry);
POWER_ACTION_POLICY = packed record Action: DWORD; Flags: DWORD; EventCode: DWORD; end; PPOWER_ACTION_POLICY = ^POWER_ACTION_POLICY;
SYSTEM_POWER_LEVEL = packed record Enable: boolean; Spare: array[0..2] of byte; BatteryLevel: DWORD; PowerPolicy: POWER_ACTION_POLICY; MinSystemState: DWORD; end; PSYSTEM_POWER_LEVEL = ^SYSTEM_POWER_LEVEL;
SYSTEM_POWER_POLICY = packed record Revision: DWORD; PowerButton: POWER_ACTION_POLICY; SleepButton: POWER_ACTION_POLICY; LidClose: POWER_ACTION_POLICY; LidOpenWake: DWORD; Reserved: DWORD;
Idle: POWER_ACTION_POLICY; IdleTimeout: DWORD; IdleSensitivity: byte;
DynamicThrottle: byte;
Spare2: array[0..1] of byte;
MinSleep: DWORD; MaxSleep: DWORD; ReducedLatencySleep: DWORD; WinLogonFlags: DWORD;
Spare3: DWORD; DozeS4Timeout: DWORD;
BroadcastCapacityResolution: DWORD; DischargePolicy: array[0..NUM_DISCHARGE_POLICIES - 1] of SYSTEM_POWER_LEVEL;
VideoTimeout: DWORD; VideoDimDisplay: boolean; VideoReserved: array[0..2] of DWORD;
SpindownTimeout: DWORD;
OptimizeForPower: boolean; FanThrottleTolerance: byte; ForcedThrottle: byte; MinThrottle: byte; OverThrottled: POWER_ACTION_POLICY; dontknow: array[0..2] of byte; end; PSYSTEM_POWER_POLICY = ^SYSTEM_POWER_POLICY;
TPowerProf = class private SysPowerPolicy: PSYSTEM_POWER_POLICY; OldVideoTimeOutAc:Cardinal; function GetVideoTimeOutAc: cardinal; procedure SetVideoTimeOutAc(const Value: cardinal);
public constructor Create; destructor Destroy; override; procedure RestoreVideoTimeOutAc; property VideoTimeOutAc: cardinal read GetVideoTimeOutAc write SetVideoTimeOutAc; end;
function CallNtPowerInformation(InformationLevel: POWER_INFORMATION_LEVEL; lpInputBuffer: Pointer; nInputBufferSize: cardinal; lpOutputBuffer: Pointer; nOutputBufferSize: cardinal): NTSTATUS; stdcall;
implementation
const powrprofdll = 'powrprof.dll';
function CallNtPowerInformation; external powrprofdll Name 'CallNtPowerInformation';
constructor TPowerProf.Create; begin getmem(SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY)); OldVideoTimeOutAc:=VideoTimeOutAc; end;
destructor TPowerProf.Destroy; begin RestoreVideoTimeOutAc; if SysPowerPolicy <> nil then begin freemem(SysPowerPolicy); SysPowerPolicy:=nil; end; end;
function TPowerProf.GetVideoTimeOutAc: cardinal; begin result:=0; if SysPowerPolicy=nil then exit; if SUCCEEDED(CallNtPowerInformation(SystemPowerPolicyCurrent, nil, 0, SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY))) then Result:=SysPowerPolicy^.VideoTimeout; end;
procedure TPowerProf.RestoreVideoTimeOutAc; begin VideoTimeOutAc:=OldVideoTimeOutAc; end;
procedure TPowerProf.SetVideoTimeOutAc(const Value: cardinal); begin if SysPowerPolicy=nil then exit; SysPowerPolicy^.VideoTimeout:=Value; CallNtPowerInformation(SystemPowerPolicyAc, SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY), SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY)); end;
end. |