Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Abfragen der Eigenschaften eines Energieschemas

  Alt 21. Apr 2021, 11:50
Leider noch total unvollständig, aber ein Ansatz!
Delphi-Quellcode:
program Project20;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Winapi.Windows,
  System.SysUtils;

{
https://docs.microsoft.com/en-us/windows/win32/api/powersetting/nf-powersetting-powergetactivescheme
DWORD PowerGetActiveScheme(
  HKEY UserRootPowerKey,
  GUID **ActivePolicyGuid
);
Parameters
UserRootPowerKey

This parameter is reserved for future use and must be set to NULL.

ActivePolicyGuid

A pointer that receives a pointer to a GUID structure. Use the LocalFree function to free this memory.

Return value
Returns ERROR_SUCCESS (zero) if the call was successful, and a nonzero value if the call failed.
}

function PowerGetActiveScheme(UserRootPowerKey: HKEY; var ActivePolicyGuid: PGUID): DWORD; stdcall; external 'PowrProf.dll';

{
https://docs.microsoft.com/en-us/windows/win32/api/powersetting/nf-powersetting-powerreadacvalue
DWORD PowerReadACValue(
  HKEY      RootPowerKey,
  const GUID *SchemeGuid,
  const GUID *SubGroupOfPowerSettingsGuid,
  const GUID *PowerSettingGuid,
  PULONG    Type,
  LPBYTE    Buffer,
  LPDWORD    BufferSize
);
Parameters
RootPowerKey

This parameter is reserved for future use and must be set to NULL.

SchemeGuid

The identifier of the power scheme.

SubGroupOfPowerSettingsGuid

The subgroup of power settings. This parameter can be one of the following values defined in WinNT.h. Use NO_SUBGROUP_GUID to retrieve the setting for the default power scheme.

TABLE 1
Value   Meaning
NO_SUBGROUP_GUID
fea3413e-7e05-4911-9a71-700331f1c294
Settings in this subgroup are part of the default power scheme.
GUID_DISK_SUBGROUP
0012ee47-9041-4b5d-9b77-535fba8b1442
Settings in this subgroup control power management configuration of the system's hard disk drives.
GUID_SYSTEM_BUTTON_SUBGROUP
4f971e89-eebd-4455-a8de-9e59040e7347
Settings in this subgroup control configuration of the system power buttons.
GUID_PROCESSOR_SETTINGS_SUBGROUP
54533251-82be-4824-96c1-47b60b740d00
Settings in this subgroup control configuration of processor power management features.
GUID_VIDEO_SUBGROUP
7516b95f-f776-4464-8c53-06167f40cc99
Settings in this subgroup control configuration of the video power management features.
GUID_BATTERY_SUBGROUP
e73a048d-bf27-4f12-9731-8b2076e8891f
Settings in this subgroup control battery alarm trip points and actions.
GUID_SLEEP_SUBGROUP
238C9FA8-0AAD-41ED-83F4-97BE242C8F20
Settings in this subgroup control system sleep settings.
GUID_PCIEXPRESS_SETTINGS_SUBGROUP
501a4d13-42af-4429-9fd1-a8218c268e20
Settings in this subgroup control PCI Express settings.
PowerSettingGuid

The identifier of the power setting.

Type

A pointer to a variable that receives the type of data for the value. The possible values are listed in Registry Value Types. This parameter can be NULL and the type of data is not returned.

Buffer

A pointer to a buffer that receives the data value. If this parameter is NULL, the BufferSize parameter receives the required buffer size.

BufferSize

A pointer to a variable that contains the size of the buffer pointed to by the Buffer parameter.

If the Buffer parameter is NULL, the function returns ERROR_SUCCESS and the variable receives the required buffer size.

If the specified buffer size is not large enough to hold the requested data, the function returns ERROR_MORE_DATA and the variable receives the required buffer size.

Return value
Returns ERROR_SUCCESS (zero) if the call was successful, and a nonzero value if the call failed. If the buffer size specified by the BufferSize parameter is too small, ERROR_MORE_DATA will be returned and the DWORD pointed to by the BufferSize parameter will be filled in with the required buffer size.
}

function PowerReadACValue(RootPowerKey: HKEY; const SchemeGuid: TGUID; const SubGroupOfPowerSettingsGuid: TGUID; const PowerSettingGuid: TGUID; pType: PULONG; Buffer: LPBYTE; BufferSize: LPDWORD): DWORD; stdcall; external 'PowrProf.dll';


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}';
var
  pActivePolicyGuid: PGUID;
  Return : DWORD;
begin
  try
    pActivePolicyGuid := nil;
    Return := PowerGetActiveScheme(0, pActivePolicyGuid);
    if Return = ERROR_SUCCESS then
    begin
      Return := PowerReadACValue(0, pActivePolicyGuid, );
      if Return = ERROR_SUCCESS then
      begin

      end;
      LocalFree(pActivePolicyGuid);
    end;

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Ich tüftel noch ein wenig und update hier von Zeit zu Zeit.


....Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226 da sind die usb power settings enthalten....
Gruß vom KodeZwerg

Geändert von KodeZwerg (21. Apr 2021 um 13:53 Uhr)
  Mit Zitat antworten Zitat