Thema: Delphi Windows Leistungsindex

Einzelnen Beitrag anzeigen

PeterPanino

Registriert seit: 4. Sep 2004
1.451 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Windows Leistungsindex

  Alt 8. Sep 2018, 21:19
Kann jemand bitte mal testen, ob das auf seinem System funktioniert? Auf meinem System funktioniert es nämlich nicht - Ergebnis ist immer -1,00

Delphi-Quellcode:
program TestConsoleApplication;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  CodeSiteLogging,
  WbemScripting_TLB,
  ActiveX,
  System.Variants,
  System.SysUtils;

function GetWMIstring(wmiHost, wmiClass, wmiProperty: string): string;
var
  // These are all needed for the WMI querying process
  Locator: ISWbemLocator;
  Services: ISWbemServices;
  SObject: ISWbemObject;
  ObjSet: ISWbemObjectSet;
  SProp: ISWbemProperty;
  Enum: IEnumVariant;
  Value: Cardinal;
  TempObj: OleVariant;
  SN: string;
begin
  Result := '';
  try
    // Create the Location object
    Locator := CoSWbemLocator.Create;
    // Connect to the WMI service, with the root\cimv2 namespace
    Services := Locator.ConnectServer(wmiHost, 'root\cimv2', '', '', '', '', 0, nil);
    ObjSet := Services.ExecQuery('SELECT * FROM ' + wmiClass, 'WQL', wbemFlagReturnImmediately and wbemFlagForwardOnly, nil);
    Enum := (ObjSet._NewEnum) as IEnumVariant;

    while Enum.Next(1, TempObj, Value) = S_OK do
    begin

      try
        SObject := IUnknown(TempObj) as ISWBemObject;
      except
        SObject := nil;
      end;
      // Always need to free interface in TempObj
      TempObj := System.Variants.Unassigned;

      if SObject <> nil then
      begin
        SProp := SObject.Properties_.Item(wmiProperty, 0);
        SN := SProp.Get_Value;

        if not VarIsNull(SN) then
        begin
          Result := SN;
          Break;
        end;

      end;
    end;
    // Trap any exceptions (Like not having WMI installed will cause one...)
  except
  end;
end;

begin
  try

    CodeSite.Send('Start');
    CodeSite.Send('CPUScore', Format('%.2f', [StrToFloatDef(GetWMIstring('', 'Win32_WinSAT', 'CPUScore'), -1)]));
    CodeSite.Send('WinSPRLevel', Format('%.2f', [StrToFloatDef(GetWMIstring('', 'Win32_WinSAT', 'WinSPRLevel'), -1)]));

  except
    on E: Exception do
    begin
      Writeln(E.ClassName, ': ', E.Message);
      Readln;
    end;
  end;
end.

Geändert von PeterPanino ( 8. Sep 2018 um 21:22 Uhr)
  Mit Zitat antworten Zitat