1
{******************************************************************************}
3
{ Power Policy Applicator interface Unit for Object Pascal }
5
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
6
{ Corporation. All Rights Reserved. }
8
{ The original file is: powrprof.h, released June 2000. The original Pascal }
9
{ code is: PowrProf.pas, released August 2001. The initial developer of the }
10
{ Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
12
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
13
{ Marcel van Brakel. All Rights Reserved. }
15
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
17
{ You may retrieve the latest version of this file at the Project JEDI }
18
{ APILIB home page, located at http://jedi-apilib.sourceforge.net }
20
{ The contents of this file are used with permission, subject to the Mozilla }
21
{ Public License Version 1.1 (the "License"); you may not use this file except }
22
{ in compliance with the License. You may obtain a copy of the License at }
23
{ http://www.mozilla.org/MPL/MPL-1.1.html }
25
{ Software distributed under the License is distributed on an "AS IS" basis, }
26
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
27
{ the specific language governing rights and limitations under the License. }
29
{ Alternatively, the contents of this file may be used under the terms of the }
30
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
31
{ provisions of the LGPL License are applicable instead of those above. }
32
{ If you wish to allow use of your version of this file only under the terms }
33
{ of the LGPL License and not to allow others to use your version of this file }
34
{ under the MPL, indicate your decision by deleting the provisions above and }
35
{ replace them with the notice and other provisions required by the LGPL }
36
{ License. If you do not delete the provisions above, a recipient may use }
37
{ your version of this file under either the MPL or the LGPL License. }
39
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
41
{******************************************************************************}
43
// $Id: jwapowrprof.pas,v 1.1 2005/04/04 07:56:10 marco Exp $
50
{$HPPEMIT '#include "powrprof.h"'}
60
// Registry storage structures for the GLOBAL_POWER_POLICY data. There are two
61
// structures, GLOBAL_MACHINE_POWER_POLICY and GLOBAL_USER_POWER_POLICY. the
62
// GLOBAL_MACHINE_POWER_POLICY stores per machine data for which there is no UI.
63
// GLOBAL_USER_POWER_POLICY stores the per user data.
66
PGLOBAL_MACHINE_POWER_POLICY = ^GLOBAL_MACHINE_POWER_POLICY;
67
{$EXTERNALSYM PGLOBAL_MACHINE_POWER_POLICY}
68
_GLOBAL_MACHINE_POWER_POLICY = record
70
LidOpenWakeAc: SYSTEM_POWER_STATE;
71
LidOpenWakeDc: SYSTEM_POWER_STATE;
72
BroadcastCapacityResolution: ULONG;
74
{$EXTERNALSYM _GLOBAL_MACHINE_POWER_POLICY}
75
GLOBAL_MACHINE_POWER_POLICY = _GLOBAL_MACHINE_POWER_POLICY;
76
{$EXTERNALSYM GLOBAL_MACHINE_POWER_POLICY}
77
TGlobalMachinePowerPolicy = GLOBAL_MACHINE_POWER_POLICY;
78
PGlobalMachinePowerPolicy = PGLOBAL_MACHINE_POWER_POLICY;
80
PGLOBAL_USER_POWER_POLICY = ^GLOBAL_USER_POWER_POLICY;
81
{$EXTERNALSYM PGLOBAL_USER_POWER_POLICY}
82
_GLOBAL_USER_POWER_POLICY = record
84
PowerButtonAc: POWER_ACTION_POLICY;
85
PowerButtonDc: POWER_ACTION_POLICY;
86
SleepButtonAc: POWER_ACTION_POLICY;
87
SleepButtonDc: POWER_ACTION_POLICY;
88
LidCloseAc: POWER_ACTION_POLICY;
89
LidCloseDc: POWER_ACTION_POLICY;
90
DischargePolicy: array [0..NUM_DISCHARGE_POLICIES - 1] of SYSTEM_POWER_LEVEL;
93
{$EXTERNALSYM _GLOBAL_USER_POWER_POLICY}
94
GLOBAL_USER_POWER_POLICY = _GLOBAL_USER_POWER_POLICY;
95
{$EXTERNALSYM GLOBAL_USER_POWER_POLICY}
96
TGlobalUserPowerPolicy = GLOBAL_USER_POWER_POLICY;
97
PGlobalUserPowerPolicy = PGLOBAL_USER_POWER_POLICY;
99
// Structure to manage global power policies at the user level. This structure
100
// contains data which is common across all power policy profiles.
102
PGLOBAL_POWER_POLICY = ^GLOBAL_POWER_POLICY;
103
{$EXTERNALSYM PGLOBAL_POWER_POLICY}
104
_GLOBAL_POWER_POLICY = record
105
user: GLOBAL_USER_POWER_POLICY;
106
mach: GLOBAL_MACHINE_POWER_POLICY;
108
{$EXTERNALSYM _GLOBAL_POWER_POLICY}
109
GLOBAL_POWER_POLICY = _GLOBAL_POWER_POLICY;
110
{$EXTERNALSYM GLOBAL_POWER_POLICY}
111
TGlobalPowerPolicy = GLOBAL_POWER_POLICY;
112
PGlobalPowerPolicy = PGLOBAL_POWER_POLICY;
114
// Registry storage structures for the POWER_POLICY data. There are three
115
// structures, MACHINE_POWER_POLICY, MACHINE_PROCESSOR_POWER_POLICY and USER_POWER_POLICY. the
116
// MACHINE_POWER_POLICY stores per machine data for which there is no UI.
117
// USER_POWER_POLICY stores the per user data.
119
PMACHINE_POWER_POLICY = ^MACHINE_POWER_POLICY;
120
{$EXTERNALSYM PMACHINE_POWER_POLICY}
121
_MACHINE_POWER_POLICY = record
122
Revision: ULONG; // 1
123
// meaning of power action "sleep"
124
MinSleepAc: SYSTEM_POWER_STATE;
125
MinSleepDc: SYSTEM_POWER_STATE;
126
ReducedLatencySleepAc: SYSTEM_POWER_STATE;
127
ReducedLatencySleepDc: SYSTEM_POWER_STATE;
128
// parameters for dozing
129
DozeTimeoutAc: ULONG;
130
DozeTimeoutDc: ULONG;
131
DozeS4TimeoutAc: ULONG;
132
DozeS4TimeoutDc: ULONG;
133
// processor policies
134
MinThrottleAc: UCHAR;
135
MinThrottleDc: UCHAR;
136
pad1: array [0..1] of UCHAR;
137
OverThrottledAc: POWER_ACTION_POLICY;
138
OverThrottledDc: POWER_ACTION_POLICY;
140
{$EXTERNALSYM _MACHINE_POWER_POLICY}
141
MACHINE_POWER_POLICY = _MACHINE_POWER_POLICY;
142
{$EXTERNALSYM MACHINE_POWER_POLICY}
143
TMachinePowerPolicy = MACHINE_POWER_POLICY;
144
PMachinePowerPolicy = PMACHINE_POWER_POLICY;
146
PMACHINE_PROCESSOR_POWER_POLICY = ^MACHINE_PROCESSOR_POWER_POLICY;
147
{$EXTERNALSYM PMACHINE_PROCESSOR_POWER_POLICY}
148
_MACHINE_PROCESSOR_POWER_POLICY = record
149
Revision: ULONG; // 1
150
ProcessorPolicyAc: PROCESSOR_POWER_POLICY;
151
ProcessorPolicyDc: PROCESSOR_POWER_POLICY;
153
{$EXTERNALSYM _MACHINE_PROCESSOR_POWER_POLICY}
154
MACHINE_PROCESSOR_POWER_POLICY = _MACHINE_PROCESSOR_POWER_POLICY;
155
{$EXTERNALSYM MACHINE_PROCESSOR_POWER_POLICY}
156
TMachineProcessorPowerPolicy = MACHINE_PROCESSOR_POWER_POLICY;
157
PMachineProcessorPowerPolicy = PMACHINE_PROCESSOR_POWER_POLICY;
159
PUSER_POWER_POLICY = ^USER_POWER_POLICY;
160
{$EXTERNALSYM PUSER_POWER_POLICY}
161
_USER_POWER_POLICY = record
162
Revision: ULONG; // 1
163
// "system idle" detection
164
IdleAc: POWER_ACTION_POLICY;
165
IdleDc: POWER_ACTION_POLICY;
166
IdleTimeoutAc: ULONG;
167
IdleTimeoutDc: ULONG;
168
IdleSensitivityAc: UCHAR;
169
IdleSensitivityDc: UCHAR;
171
ThrottlePolicyAc: UCHAR;
172
ThrottlePolicyDc: UCHAR;
173
// meaning of power action "sleep"
174
MaxSleepAc: SYSTEM_POWER_STATE;
175
MaxSleepDc: SYSTEM_POWER_STATE;
177
Reserved: array [0..1] of ULONG;
179
VideoTimeoutAc: ULONG;
180
VideoTimeoutDc: ULONG;
181
// hard disk policies
182
SpindownTimeoutAc: ULONG;
183
SpindownTimeoutDc: ULONG;
184
// processor policies
185
OptimizeForPowerAc: ByteBool;
186
OptimizeForPowerDc: ByteBool;
187
FanThrottleToleranceAc: UCHAR;
188
FanThrottleToleranceDc: UCHAR;
189
ForcedThrottleAc: UCHAR;
190
ForcedThrottleDc: UCHAR;
192
{$EXTERNALSYM _USER_POWER_POLICY}
193
USER_POWER_POLICY = _USER_POWER_POLICY;
194
{$EXTERNALSYM USER_POWER_POLICY}
195
TUserPowerPolicy = USER_POWER_POLICY;
196
PUserPowerPolicy = PUSER_POWER_POLICY;
198
// Structure to manage power policies at the user level. This structure
199
// contains data which is unique across power policy profiles.
201
PPOWER_POLICY = ^POWER_POLICY;
202
{$EXTERNALSYM PPOWER_POLICY}
203
_POWER_POLICY = record
204
user: USER_POWER_POLICY;
205
mach: MACHINE_POWER_POLICY;
207
{$EXTERNALSYM _POWER_POLICY}
208
POWER_POLICY = _POWER_POLICY;
209
{$EXTERNALSYM POWER_POLICY}
210
TPowerPolicy = POWER_POLICY;
211
PPowerPolicy = PPOWER_POLICY;
213
// Constants for GlobalFlags
216
EnableSysTrayBatteryMeter = $01;
217
{$EXTERNALSYM EnableSysTrayBatteryMeter}
218
EnableMultiBatteryDisplay = $02;
219
{$EXTERNALSYM EnableMultiBatteryDisplay}
220
EnablePasswordLogon = $04;
221
{$EXTERNALSYM EnablePasswordLogon}
222
EnableWakeOnRing = $08;
223
{$EXTERNALSYM EnableWakeOnRing}
224
EnableVideoDimDisplay = $10;
225
{$EXTERNALSYM EnableVideoDimDisplay}
227
// This constant is passed as a uiID to WritePwrScheme.
229
NEWSCHEME = UINT(-1);
230
{$EXTERNALSYM NEWSCHEME}
232
// Prototype for EnumPwrSchemes callback proceedures.
235
PWRSCHEMESENUMPROC = function(uiIndex: UINT; dwName: DWORD; sName: LPTSTR; dwDesc: DWORD; sDesc: LPTSTR; pp: PPOWER_POLICY; lParam: LPARAM): ByteBool; stdcall;
236
{$EXTERNALSYM PWRSCHEMESENUMPROC}
237
PFNNTINITIATEPWRACTION = function(pPowerAction: POWER_ACTION; SystemPowerState: SYSTEM_POWER_STATE; u: ULONG; b: ByteBool): ByteBool; stdcall;
238
{$EXTERNALSYM PFNNTINITIATEPWRACTION}
240
// Public function prototypes
242
function GetPwrDiskSpindownRange(var RangeMax, RangeMin: UINT): ByteBool; stdcall;
243
{$EXTERNALSYM GetPwrDiskSpindownRange}
244
function EnumPwrSchemes(lpfnPwrSchemesEnumProc: PWRSCHEMESENUMPROC; lParam: LPARAM): ByteBool; stdcall;
245
{$EXTERNALSYM EnumPwrSchemes}
246
function ReadGlobalPwrPolicy(var pGlobalPowerPolicy: GLOBAL_POWER_POLICY): ByteBool; stdcall;
247
{$EXTERNALSYM ReadGlobalPwrPolicy}
248
function ReadPwrScheme(uiID: UINT; var pPowerPolicy: POWER_POLICY): ByteBool; stdcall;
249
{$EXTERNALSYM ReadPwrScheme}
250
function WritePwrScheme(puiID: PUINT; lpszName, lpszDescription: LPTSTR; const pPowerPolicy: POWER_POLICY): ByteBool; stdcall;
251
{$EXTERNALSYM WritePwrScheme}
252
function WriteGlobalPwrPolicy(const pGlobalPowerPolicy: GLOBAL_POWER_POLICY): ByteBool; stdcall;
253
{$EXTERNALSYM WriteGlobalPwrPolicy}
254
function DeletePwrScheme(uiIndex: UINT): ByteBool; stdcall;
255
{$EXTERNALSYM DeletePwrScheme}
256
function GetActivePwrScheme(var puiID: UINT): ByteBool; stdcall;
257
{$EXTERNALSYM GetActivePwrScheme}
258
function SetActivePwrScheme(uiID: UINT; pGlobalPowerPolicy: PGLOBAL_POWER_POLICY; pPowerPolicy: PPOWER_POLICY): ByteBool; stdcall;
259
{$EXTERNALSYM SetActivePwrScheme}
260
function GetPwrCapabilities(var lpSystemPowerCapabilities: SYSTEM_POWER_CAPABILITIES): ByteBool; stdcall;
261
{$EXTERNALSYM GetPwrCapabilities}
262
function IsPwrSuspendAllowed: ByteBool; stdcall;
263
{$EXTERNALSYM IsPwrSuspendAllowed}
264
function IsPwrHibernateAllowed: ByteBool; stdcall;
265
{$EXTERNALSYM IsPwrHibernateAllowed}
266
function IsPwrShutdownAllowed: ByteBool; stdcall;
267
{$EXTERNALSYM IsPwrShutdownAllowed}
268
function IsAdminOverrideActive(pAdministratorPowerPolicy: PADMINISTRATOR_POWER_POLICY): ByteBool; stdcall;
269
{$EXTERNALSYM IsAdminOverrideActive}
270
function SetSuspendState(Hibernate, ForceCritical, DisableWakeEvent: ByteBool): ByteBool; stdcall;
271
{$EXTERNALSYM SetSuspendState}
272
function GetCurrentPowerPolicies(pGlobalPowerPolicy: PGLOBAL_POWER_POLICY; pPowerPolicy: PPOWER_POLICY): ByteBool; stdcall;
273
{$EXTERNALSYM GetCurrentPowerPolicies}
274
function CanUserWritePwrScheme: ByteBool; stdcall;
275
{$EXTERNALSYM CanUserWritePwrScheme}
276
function ReadProcessorPwrScheme(uiID: UINT; var pMachineProcessorPowerPolicy: MACHINE_PROCESSOR_POWER_POLICY): ByteBool; stdcall;
277
{$EXTERNALSYM ReadProcessorPwrScheme}
278
function WriteProcessorPwrScheme(uiID: UINT; const pMachineProcessorPowerPolicy: MACHINE_PROCESSOR_POWER_POLICY): ByteBool; stdcall;
279
{$EXTERNALSYM WriteProcessorPwrScheme}
280
function ValidatePowerPolicies(GlobalPolicy: PGLOBAL_POWER_POLICY; Policy: PPOWER_POLICY): ByteBool; stdcall;
281
{$EXTERNALSYM ValidatePowerPolicies}
283
function CallNtPowerInformation(InformationLeveL: POWER_INFORMATION_LEVEL; lpInputBuffer: PVOID; nInputBufferSize: ULONG; lpOutputBuffer: PVOID; nOutputBufferSize: ULONG): NTSTATUS; stdcall;
284
{$EXTERNALSYM CallNtPowerInformation}
289
powrproflib = 'powrprof.dll';
291
{$IFDEF DYNAMIC_LINK}
294
_GetPwrDiskSpindownRange: Pointer;
296
function GetPwrDiskSpindownRange;
298
GetProcedureAddress(_GetPwrDiskSpindownRange, powrproflib, 'GetPwrDiskSpindownRange');
302
JMP [_GetPwrDiskSpindownRange]
307
_EnumPwrSchemes: Pointer;
309
function EnumPwrSchemes;
311
GetProcedureAddress(_EnumPwrSchemes, powrproflib, 'EnumPwrSchemes');
315
JMP [_EnumPwrSchemes]
320
_ReadGlobalPwrPolicy: Pointer;
322
function ReadGlobalPwrPolicy;
324
GetProcedureAddress(_ReadGlobalPwrPolicy, powrproflib, 'ReadGlobalPwrPolicy');
328
JMP [_ReadGlobalPwrPolicy]
333
_ReadPwrScheme: Pointer;
335
function ReadPwrScheme;
337
GetProcedureAddress(_ReadPwrScheme, powrproflib, 'ReadPwrScheme');
346
_WritePwrScheme: Pointer;
348
function WritePwrScheme;
350
GetProcedureAddress(_WritePwrScheme, powrproflib, 'WritePwrScheme');
354
JMP [_WritePwrScheme]
359
_WriteGlobalPwrPolicy: Pointer;
361
function WriteGlobalPwrPolicy;
363
GetProcedureAddress(_WriteGlobalPwrPolicy, powrproflib, 'WriteGlobalPwrPolicy');
367
JMP [_WriteGlobalPwrPolicy]
372
_DeletePwrScheme: Pointer;
374
function DeletePwrScheme;
376
GetProcedureAddress(_DeletePwrScheme, powrproflib, 'DeletePwrScheme');
380
JMP [_DeletePwrScheme]
385
_GetActivePwrScheme: Pointer;
387
function GetActivePwrScheme;
389
GetProcedureAddress(_GetActivePwrScheme, powrproflib, 'GetActivePwrScheme');
393
JMP [_GetActivePwrScheme]
398
_SetActivePwrScheme: Pointer;
400
function SetActivePwrScheme;
402
GetProcedureAddress(_SetActivePwrScheme, powrproflib, 'SetActivePwrScheme');
406
JMP [_SetActivePwrScheme]
411
_GetPwrCapabilities: Pointer;
413
function GetPwrCapabilities;
415
GetProcedureAddress(_GetPwrCapabilities, powrproflib, 'GetPwrCapabilities');
419
JMP [_GetPwrCapabilities]
424
_IsPwrSuspendAllowed: Pointer;
426
function IsPwrSuspendAllowed;
428
GetProcedureAddress(_IsPwrSuspendAllowed, powrproflib, 'IsPwrSuspendAllowed');
432
JMP [_IsPwrSuspendAllowed]
437
_IsPwrHibernateAllowed: Pointer;
439
function IsPwrHibernateAllowed;
441
GetProcedureAddress(_IsPwrHibernateAllowed, powrproflib, 'IsPwrHibernateAllowed');
445
JMP [_IsPwrHibernateAllowed]
450
_IsPwrShutdownAllowed: Pointer;
452
function IsPwrShutdownAllowed;
454
GetProcedureAddress(_IsPwrShutdownAllowed, powrproflib, 'IsPwrShutdownAllowed');
458
JMP [_IsPwrShutdownAllowed]
463
_IsAdminOverrideActive: Pointer;
465
function IsAdminOverrideActive;
467
GetProcedureAddress(_IsAdminOverrideActive, powrproflib, 'IsAdminOverrideActive');
471
JMP [_IsAdminOverrideActive]
476
_SetSuspendState: Pointer;
478
function SetSuspendState;
480
GetProcedureAddress(_SetSuspendState, powrproflib, 'SetSuspendState');
484
JMP [_SetSuspendState]
489
_GetCurrentPowerPolicies: Pointer;
491
function GetCurrentPowerPolicies;
493
GetProcedureAddress(_GetCurrentPowerPolicies, powrproflib, 'GetCurrentPowerPolicies');
497
JMP [_GetCurrentPowerPolicies]
502
_CanUserWritePwrScheme: Pointer;
504
function CanUserWritePwrScheme;
506
GetProcedureAddress(_CanUserWritePwrScheme, powrproflib, 'CanUserWritePwrScheme');
510
JMP [_CanUserWritePwrScheme]
515
_ReadProcessorPwrScheme: Pointer;
517
function ReadProcessorPwrScheme;
519
GetProcedureAddress(_ReadProcessorPwrScheme, powrproflib, 'ReadProcessorPwrScheme');
523
JMP [_ReadProcessorPwrScheme]
528
_WriteProcessorPwrScheme: Pointer;
530
function WriteProcessorPwrScheme;
532
GetProcedureAddress(_WriteProcessorPwrScheme, powrproflib, 'WriteProcessorPwrScheme');
536
JMP [_WriteProcessorPwrScheme]
541
_ValidatePowerPolicies: Pointer;
543
function ValidatePowerPolicies;
545
GetProcedureAddress(_ValidatePowerPolicies, powrproflib, 'ValidatePowerPolicies');
549
JMP [_ValidatePowerPolicies]
554
_CallNtPowerInformation: Pointer;
556
function CallNtPowerInformation;
558
GetProcedureAddress(_CallNtPowerInformation, powrproflib, 'CallNtPowerInformation');
562
JMP [_CallNtPowerInformation]
568
function GetPwrDiskSpindownRange; external powrproflib name 'GetPwrDiskSpindownRange';
569
function EnumPwrSchemes; external powrproflib name 'EnumPwrSchemes';
570
function ReadGlobalPwrPolicy; external powrproflib name 'ReadGlobalPwrPolicy';
571
function ReadPwrScheme; external powrproflib name 'ReadPwrScheme';
572
function WritePwrScheme; external powrproflib name 'WritePwrScheme';
573
function WriteGlobalPwrPolicy; external powrproflib name 'WriteGlobalPwrPolicy';
574
function DeletePwrScheme; external powrproflib name 'DeletePwrScheme';
575
function GetActivePwrScheme; external powrproflib name 'GetActivePwrScheme';
576
function SetActivePwrScheme; external powrproflib name 'SetActivePwrScheme';
577
function GetPwrCapabilities; external powrproflib name 'GetPwrCapabilities';
578
function IsPwrSuspendAllowed; external powrproflib name 'IsPwrSuspendAllowed';
579
function IsPwrHibernateAllowed; external powrproflib name 'IsPwrHibernateAllowed';
580
function IsPwrShutdownAllowed; external powrproflib name 'IsPwrShutdownAllowed';
581
function IsAdminOverrideActive; external powrproflib name 'IsAdminOverrideActive';
582
function SetSuspendState; external powrproflib name 'SetSuspendState';
583
function GetCurrentPowerPolicies; external powrproflib name 'GetCurrentPowerPolicies';
584
function CanUserWritePwrScheme; external powrproflib name 'CanUserWritePwrScheme';
585
function ReadProcessorPwrScheme; external powrproflib name 'ReadProcessorPwrScheme';
586
function WriteProcessorPwrScheme; external powrproflib name 'WriteProcessorPwrScheme';
587
function ValidatePowerPolicies; external powrproflib name 'ValidatePowerPolicies';
588
function CallNtPowerInformation; external powrproflib name 'CallNtPowerInformation';
590
{$ENDIF DYNAMIC_LINK}