unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj,
ActiveX;
const PWR_PROF = '
PowrProf.dll';
{$EXTERNALSYM _POWER_DATA_ACCESSOR}
const NO_SUBGROUP_GUID: TGUID = '
{fea3413e-7e05-4911-9a71-700331f1c294}';
GUID_DISK_SUBGROUP: TGUID = '
{0012ee47-9041-4b5d-9b77-535fba8b1442}';
GUID_SYSTEM_BUTTON_SUBGROUP: TGUID = '
{4f971e89-eebd-4455-a8de-9e59040e7347}';
GUID_PROCESSOR_SETTINGS_SUBGROUP: TGUID = '
{54533251-82be-4824-96c1-47b60b740d00}';
GUID_VIDEO_SUBGROUP: TGUID = '
{7516b95f-f776-4464-8c53-06167f40cc99}';
GUID_BATTERY_SUBGROUP: TGUID = '
{e73a048d-bf27-4f12-9731-8b2076e8891f}';
GUID_SLEEP_SUBGROUP: TGUID = '
{238C9FA8-0AAD-41ED-83F4-97BE242C8F20}';
GUID_PCIEXPRESS_SETTINGS_SUBGROUP: TGUID = '
{501a4d13-42af-4429-9fd1-a8218c268e20}';
type _POWER_DATA_ACCESSOR = (
ACCESS_AC_POWER_SETTING_INDEX = 0,
// 0x0
ACCESS_DC_POWER_SETTING_INDEX = 1,
// 0x1
ACCESS_SCHEME = 16,
// 0x10
ACCESS_SUBGROUP = 17,
// 0x11
ACCESS_INDIVIDUAL_SETTING = 18,
// 0x12
ACCESS_ACTIVE_SCHEME = 19,
// 0x13
ACCESS_CREATE_SCHEME = 20
// 0x14
);
{$EXTERNALSYM POWER_DATA_ACCESSOR}
POWER_DATA_ACCESSOR = _POWER_DATA_ACCESSOR;
{$EXTERNALSYM PPOWER_DATA_ACCESSOR}
PPOWER_DATA_ACCESSOR = ^_POWER_DATA_ACCESSOR;
TForm1 =
class(TForm)
Button1: TButton;
Memo: TMemo;
Button2: TButton;
Button3: TButton;
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
active_guid : TGUID;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
{$EXTERNALSYM PowerSetActiveScheme}
function PowerSetActiveScheme(UserRootPowerKey: HKEY;
const SchemeGUID: PGUID):
DWORD;
stdcall;
external PWR_PROF;
{$EXTERNALSYM PowerEnumerate}
function PowerEnumerate(UserRootPowerKey: HKEY;
const SchemeGuid: PGUID;
const SubGroupOfPowerSettingGuid: PGUID; AccessFlag: POWER_DATA_ACCESSOR;
Index: ULONG; Buffer: PUCHAR; BufferSize: PDWORD):
DWORD;
stdcall;
external PWR_PROF;
{$EXTERNALSYM PowerGetActiveScheme}
function PowerGetActiveScheme(UserRootPowerKey: HKEY; Buffer: PUCHAR): DWORD;
stdcall;
external PWR_PROF;
{$EXTERNALSYM PowerReadDescription}
function PowerReadDescription(UserRootPowerKey: HKEY;
const SchemeGuid: PGUID;
const SubGroupOfPowerSettingGuid: PGUID;
const PowerSettingGuid: PGUID;
Buffer: PUCHAR; BufferSize: PDWORD):
DWORD;
stdcall;
external PWR_PROF;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var res, size: DWORD;
i: ULONG;
tmp: TGUID;
begin
i := 0;
size := SizeOf(TGUID);
repeat
res := PowerEnumerate(0,
nil,
nil, ACCESS_SCHEME, i, @tmp, @size);
if res = ERROR_SUCCESS
then begin
Memo.Lines.Add(GUIDToString(tmp));
active_guid := tmp;
end
else Memo.Lines.Add(inttostr(res));
Inc(i);
until res <> ERROR_SUCCESS;
end;
procedure TForm1.Button2Click(Sender: TObject);
var res: DWORD;
tmp: TGUID;
begin
res := PowerGetActiveScheme(0, @tmp);
if res = ERROR_SUCCESS
then begin
Memo.Lines.Add(GUIDToString(tmp));
active_guid := tmp;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var res, size: DWORD;
tmp: TGUID;
begin
size := SizeOf(PGUID);
// res := PowerReadDescription(0, active_guid, nil, nil, @tmp, @size);
if res = ERROR_SUCCESS
then
Memo.Lines.Add(GUIDToString(tmp))
else
Memo.Lines.Add('
Fehler -> '+GUIDToString(tmp));
end;
end.