program Project5;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Winapi.Windows;
function PowerGetActiveScheme(UserRootPowerKey: HKEY;
var ActivePolicyGuid: PGUID): DWORD;
stdcall;
external '
PowrProf.dll'
name '
PowerGetActiveScheme';
//function PowerReadACValue(RootPowerKey: HKEY; const SchemeGuid: TGUID; const SubGroupOfPowerSettingsGuid: TGUID;
// const PowerSettingGuid: TGUID; pType: PULONG; Buffer: LPBYTE; BufferSize: LPDWORD): DWORD; stdcall; external 'PowrProf.dll';
function PowerReadACValueIndex(RootPowerKey: HKEY;
const SchemeGuid: TGUID;
const SubGroupOfPowerSettingsGuid: TGUID;
const PowerSettingGuid: TGUID; AcValueIndex: LPDWORD): DWORD;
stdcall;
external '
PowrProf.dll';
const
USBSetting: TGUID = '
{2a737441-1930-4402-8d77-b2bebba308a3}';
// # USB settings
USBSelectiveSuspendSetting: TGUID = '
{48e6b7a6-50f5-4782-a5d4-53bb8f07e226}';
// # USB selective suspend setting
var
ActivePolicyGuidPtr: PGUID;
res: DWORD;
AcValueIndex: DWORD;
DbgText:
string;
begin
try
ActivePolicyGuidPtr :=
nil;
res := PowerGetActiveScheme(0, ActivePolicyGuidPtr);
if (res = ERROR_SUCCESS)
and Assigned(ActivePolicyGuidPtr)
then
begin
Writeln('
Active Power Scheme GUID: ', TGUID(ActivePolicyGuidPtr^).ToString);
AcValueIndex := 123456789;
// Vorinitialisieren nur um zu sehen, das sich der Wert ändert!
res := PowerReadACValueIndex(0, TGUID(ActivePolicyGuidPtr^), USBSetting, USBSelectiveSuspendSetting, @AcValueIndex);
if res = ERROR_SUCCESS
then
begin
Writeln;
DbgText := Format('
USB settings: %s' + sLineBreak + '
USB selective suspend setting: %s' + sLineBreak +
'
AC Value Index: %d', [USBSetting.ToString, USBSelectiveSuspendSetting.ToString, AcValueIndex]);
Writeln(DbgText);
end;
LocalFree(ActivePolicyGuidPtr);
end;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
Readln;
end.