![]() |
Abfragen der Eigenschaften eines Energieschemas
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
ich möchte gerne herausfinden, welche Eigenschaften ein Energieschema aufweist, welches in den Energieoptionen der Windows-Systemsteuerung eingestellt ist. Wichtig ist hier vor allem die untere Tabelle, also wann Monitor & Festplatten jeweils im Netz- und Batteriebetrieb abgeschaltet werden sollen und wann der Standby & Ruhezustand jeweils im Netz- und Batteriebetrieb aktiviert werden sollen (siehe Screenshot anbei). Ich habe ![]() Nun suche ich aber eine Möglichkeit, die einzelnen Optionen eines Energieschemas zu ermitteln ? Kennt jemand einen Weg entweder über die Windows API oder Registry ? Danke und Grüße |
Re: Abfragen der Eigenschaften eines Energieschemas
Hallo,
![]() |
Re: Abfragen der Eigenschaften eines Energieschemas
Danke, dieser Ansatz ist schon mal sehr gut, und ich habe das ganze auch unter Windows XP getestet.
Unter Vista scheinen aber andere Funktionen notwendig zu sein, da die Ergebnisse hier nicht stimmen. |
Re: Abfragen der Eigenschaften eines Energieschemas
Unter Vista heißt das ganze übrigens Energiesparplan.
Nun verwende ich mithilfe der Jedi-Bibliothek verschiedene Funktionen, um die Daten eines Energiesparplans auszulesen (hier das Wichtigste meines Codes):
Delphi-Quellcode:
Das ganze funktioniert unter Windows XP auch fehlerfrei, unter Vista werden aber vollkommen falsche Werte angezeigt. Ich erhalte hier bspw. folgendes:
USES JwaPowrProf, Dialogs;
VAR uiID : UINT; ActiveSchemaIndex : LPDWORD; CurrentPowerPolicy : POWER_POLICY; Name, Desc : STRING; BEGIN IF GetActivePwrScheme(uiID) = True THEN BEGIN IF GetNamePowerScheme(uiID, Name, Desc) = True THEN BEGIN IF ReadPwrScheme(uiID, CurrentPowerPolicy) = True THEN BEGIN ShowMessage('Monitorabschaltung im Batteriebetrieb nach '+IntToStr(CurrentPowerPolicy.user.VideoTimeoutDc DIV 60)+' Minuten'); ShowMessage('Festplattenabschaltung im Batteriebetrieb nach '+IntToStr(CurrentPowerPolicy.user.SpindownTimeoutDc DIV 60)+' Minuten'); ShowMessage('Standby im Batteriebetrieb nach '+IntToStr(CurrentPowerPolicy.user.IdleTimeoutDc DIV 60)+' Minuten'); END; END; END; END; Bildschirm: nach 5 Minuten abschalten (obwohl 1 Stunde eingestellt ist) Festplatte: nach 10 Minuten abschalten (obwohl 15 Minuten eingestellt sind) Standby: nach 5 Minuten aktivieren (obwohl nie eingestellt ist) Arbeiten die Jedi-Funktionen wirklich fehlerhaft, oder woran kann das liegen ? Ich hatte auch mal den Registry-Weg versucht, hier müsste aber der binäre Schlüssel "Policies" in HKEY_CURRENT_USER/Control Panel/PowerCfg/PowerPolicies" ausgewertet werden, und dieser besteht aus 80 hexadezimalen undokumentierten Werten. Von daher dachte ich schon, dass die Jedi-Funktionen nicht nur unter XP funktionieren. Wer kann hier helfen ? |
AW: Abfragen der Eigenschaften eines Energieschemas
<<Push>>
Hi Zusammen, ich habe bei unseren Anwendern das Problem, dass bei aktivierter Energiesparoption für USB-Geräte sich ein Gerät weg hängt. Nun wollte ich schlicht prüfen, ob diese Option eingestellt ist und dann in der Software anzeigen lassen "das geht so nicht, mach das aus". Da wir die Jedi-Komponenten nicht verwenden, wollte ich fragen, ob da schonmal jemand mit Erfahrung gesammelt hat. Leider finde ich da kaum Code-Schnipsel zu (nur in C) und mein erster Versuch
Delphi-Quellcode:
fliegt auch gleich mit einer Zugriffsverletzung raus. So geht es also schonmal nicht.
uses Windows;
... function PowerGetActiveScheme(TheKey : HKEY; var theGuid : PGUID) : DWORD; external 'PowrProf.dll' name 'PowerGetActiveScheme'; ... var theGuid : PGUID; res : DWord; ... res := PowerGetActiveScheme(0, theGuid); // <- Zugriffsverletzung if (res = ERROR_SUCCESS) then try LocalFree(theGuid); except end; ... In den aktuellen Jedi-Quellen ![]() ![]() Konnte ich den Befehl "PowerGetActiveScheme" schonmal nicht finden. Auf jeden Fall bis hierhin schonmal Danke für die Zeit. Mit freundlichem Gruß Incocnito |
AW: Abfragen der Eigenschaften eines Energieschemas
Leider noch total unvollständig, aber ein Ansatz!
Delphi-Quellcode:
Ich tüftel noch ein wenig und update hier von Zeit zu Zeit.
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. ....
Delphi-Quellcode:
da sind die usb power settings enthalten....
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226
|
AW: Abfragen der Eigenschaften eines Energieschemas
Jo, das fehlende
Delphi-Quellcode:
ist die Ursache, wie KodeZwerg skizziert hat.
stdcall;
Delphi-Quellcode:
Ergibt bei mir:
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'; var ActivePolicyGuidPtr: PGUID; res: DWORD; 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); LocalFree(ActivePolicyGuidPtr); end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end.
Code:
Active Power Scheme GUID: {381B4222-F694-41F0-9685-FF5BB260DF2E}
|
AW: Abfragen der Eigenschaften eines Energieschemas
@TiGü: einen tipp wie dein/mein/unser code weitergeht damit man auslesen kann ob was aktiviert ist?
ich stecke beim PowerReadACValue() fest :-( |
AW: Abfragen der Eigenschaften eines Energieschemas
Ich hatte mich damit mal in Rahmen eines Powershell-Skripts beschäftigt, welches mit dem Windows-Tool powercfg.exe redet.
Es ist wirklich eine API aus der Hölle. :evil: Probiere mal lieber die Index-Funktionen:
Delphi-Quellcode:
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. |
AW: Abfragen der Eigenschaften eines Energieschemas
Was Incognito aber eigentlich sucht - so vermute ich - ist der Haken den man im
Geräte-Manager unter USB-Controller -> HIER_DEIN_USB_GERÄT/HUB -> Rechter Mausklick -> Kontextmenü -> Eigenschaften -> Tab Energieverwaltung -> Haken "Computer kann das Gerät ausschalten, um Energie zu sparen" findet. |
AW: Abfragen der Eigenschaften eines Energieschemas
Zitat:
Zitat:
du bist ein :angel: und ja, hölle trifft es ganz gut :lol: danke für diesen tollen beitrag!! :thumb: |
AW: Abfragen der Eigenschaften eines Energieschemas
Vielen Dank Leute.
Damit klappt es. Theoretisch geht zwar auch:
Delphi-Quellcode:
aber die Verwendung von Reg_SZ, was ja eigendlich auf einen String verweist verwirrt mich zu sehr
iType_1 := REG_SZ;
iBufferSize := 255; GetMem(buffer_1, iBufferSize); res := PowerReadACValue( 0, pActivePolicyGuid^, USBSetting, USBSelectiveSuspendSetting, @iType_1, buffer_1, @iBufferSize ); if (res = ERROR_SUCCESS) then begin engState.LastCheck := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now()); engState.UsbEng := (buffer_1^ = 1); end; daher habe ich das dann so gelöst:
Delphi-Quellcode:
Zumal ich bei der ersten Lösung theoretisch auch noch auf den Rückgabewert "ERROR_MORE_DATA"
AcValueIndex := 0;
res := PowerReadACValueIndex( 0, TGUID(pActivePolicyGuid^), // Referenzwert USBSetting, USBSelectiveSuspendSetting, // Pfad zu den Daten @AcValueIndex // Rückgabewert ); if (res = ERROR_SUCCESS) then begin engState.LastCheck := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now()); engState.UsbEng := (AcValueIndex = 1); end; prüfen müsste. Zum Thema "Einstellung aus Gerätemanager": Ne, bei der Einrichtung unserer Server sind die Techniker angewiesen die Energieoptionen entsprechend anzupassen, da dies immer wieder Probleme macht. Hiermit könnte man prüfen, ob beim Kunden dieser Wert (von deren Technikern) wieder geändert wird. Ja, theoretisch könnte man auch alle einzelnen Geräte, welche Fehler produzieren wenn man diese in den Energiesparmodus schickt, einzeln über den Gerätemanager rausnehmen, aber der Verwaltungsaufwand ist zu hoch und die Fehlerquellen multiplizierfen sich hier ja auch. Das ist zwar mit der groben Kelle, aber mal ehrlich, wer will das bei allen Kunden bis ins letzte Detail korrekt einstellen müssen. Von eigenmächtigem Austausch irgendwelcher Hardware mal ganz abgesehen. Wie gesagt. Für mich sieht die Lösung schon sehr gut aus. Ich teste das mal die Tage. Vielen Dank nochmal für die echt schnelle Hilfe. Liebe Grüße Incocnito |
AW: Abfragen der Eigenschaften eines Energieschemas
In meinem Kopf dreht sich alles, aber irgendwie bekomme ich (hoffentlich auch das korrekte) ein Ergebnis.
Falls jemand verrückt genug ist das mal zu überprüfen wäre ich echt erleichtert!!
Delphi-Quellcode:
Bei mir kommt folgendes raus:
program Project20;
{$APPTYPE CONSOLE} {$R *.res} uses Winapi.Windows, System.SysUtils, System.Classes; { 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/powrprof/nf-powrprof-powerreaddescription DWORD PowerReadDescription( HKEY RootPowerKey, const GUID *SchemeGuid, const GUID *SubGroupOfPowerSettingsGuid, const GUID *PowerSettingGuid, PUCHAR 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 refer to 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 that is being used. Buffer A pointer to a buffer that receives the description. If this parameter is NULL, the BufferSize parameter receives the required buffer size. The strings returned are all wide (Unicode) strings. 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, the function returns ERROR_SUCCESS and the DWORD pointed to by the BufferSize parameter is filled in with the required buffer size. } function PowerReadDescription(RootPowerKey: HKEY; const SchemeGuid: TGUID; const SubGroupOfPowerSettingsGuid: TGUID; const PowerSettingGuid: TGUID; Buffer: PUCHAR; BufferSize: LPDWORD): DWORD; stdcall; external 'PowrProf.dll'; { https://docs.microsoft.com/en-us/windows/win32/api/powrprof/nf-powrprof-powerreadacvalueindex DWORD PowerReadACValueIndex( HKEY RootPowerKey, const GUID *SchemeGuid, const GUID *SubGroupOfPowerSettingsGuid, const GUID *PowerSettingGuid, LPDWORD AcValueIndex ); 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 refer to 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. AcValueIndex A pointer to a variable that receives the AC value index. Return value Returns ERROR_SUCCESS (zero) if the call was successful, and a nonzero value if the call failed. } 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 pActivePolicyGuid: PGUID; Return : DWORD; Buffer: PWideChar; BufferSize: DWORD; AcValueIndex: DWORD; begin try pActivePolicyGuid := nil; Return := PowerGetActiveScheme(0, pActivePolicyGuid); if Return = ERROR_SUCCESS then begin Return := PowerReadDescription(0, pActivePolicyGuid^, USBSetting, USBSelectiveSuspendSetting, nil, @BufferSize); if Return = ERROR_SUCCESS then begin GetMem(Buffer, BufferSize); Return := PowerReadDescription(0, pActivePolicyGuid^, USBSetting, USBSelectiveSuspendSetting, Pointer(Buffer), @BufferSize); if Return = ERROR_SUCCESS then begin WriteLn('BufferSize: ' + IntToStr(BufferSize)); WriteLn('Beschreibung: ' + Buffer); end; FreeMem(Buffer, BufferSize); end; Return := PowerReadACValueIndex(0, pActivePolicyGuid^, USBSetting, USBSelectiveSuspendSetting, @AcValueIndex); if Return = ERROR_SUCCESS then begin WriteLn('Wert: ' + IntToStr(AcValueIndex)); end; LocalFree(pActivePolicyGuid); end; ReadLn; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. BufferSize: 156 Beschreibung: Geben Sie an, ob selektives USB-Energiesparen aktiviert oder deaktiviert ist. Wert: 1 //edit hatte TOTAL TiGüs code vergessen einzubauen. Nun klappt auch bei mir alles. |
AW: Abfragen der Eigenschaften eines Energieschemas
Zitat:
Wie ich weiter oben erwähnte, standen wir vor einer ähnlichen Herausforderung. Ich habe dir in PasteBin einen Auszug aus meinen PowerShell-Skript gepostet: ![]() Ist vielleicht ein guter Starting Point, um es auf deine Bedürfnisse anzupassen. Die deutschen Kommentare sind aus unserer Anleitung, die wir davor benutzt haben und damit man die Einstellung in der normalen Windows-Oberfläche wiederfindet. Da hier zum Großteil nur stumpf mit der powercfg.exe geredet wird, ist eine Umsetzung mit der Windows-Batch-Skriptsprache grundsätzlich möglich, wenn gewünscht. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz