Tuesday, October 23, 2018

How to Get Cache Memory Information in Delphi


program GetWMI_Info;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

procedure  GetWin32_CacheMemoryInfo;
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_CacheMemory','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('Access                         %d',[Integer(FWbemObject.Access)]));// Uint16
    Writeln(Format('AdditionalErrorData            %d',[Integer(FWbemObject.AdditionalErrorData)]));// Uint8
    Writeln(Format('Associativity                  %d',[Integer(FWbemObject.Associativity)]));// Uint16
    Writeln(Format('Availability                   %d',[Integer(FWbemObject.Availability)]));// Uint16
    Writeln(Format('BlockSize                      %d',[Integer(FWbemObject.BlockSize)]));// Uint64
    Writeln(Format('CacheSpeed                     %d',[Integer(FWbemObject.CacheSpeed)]));// Uint32
    Writeln(Format('CacheType                      %d',[Integer(FWbemObject.CacheType)]));// Uint16
    Writeln(Format('Caption                        %s',[String(FWbemObject.Caption)]));// String
    Writeln(Format('ConfigManagerErrorCode         %d',[Integer(FWbemObject.ConfigManagerErrorCode)]));// Uint32
    Writeln(Format('ConfigManagerUserConfig        %s',[String(FWbemObject.ConfigManagerUserConfig)]));// Boolean
    Writeln(Format('CorrectableError               %s',[String(FWbemObject.CorrectableError)]));// Boolean
    Writeln(Format('CreationClassName              %s',[String(FWbemObject.CreationClassName)]));// String
    Writeln(Format('CurrentSRAM                    %d',[Integer(FWbemObject.CurrentSRAM)]));// Uint16
    Writeln(Format('Description                    %s',[String(FWbemObject.Description)]));// String
    Writeln(Format('DeviceID                       %s',[String(FWbemObject.DeviceID)]));// String
    Writeln(Format('EndingAddress                  %d',[Integer(FWbemObject.EndingAddress)]));// Uint64
    Writeln(Format('ErrorAccess                    %d',[Integer(FWbemObject.ErrorAccess)]));// Uint16
    Writeln(Format('ErrorAddress                   %d',[Integer(FWbemObject.ErrorAddress)]));// Uint64
    Writeln(Format('ErrorCleared                   %s',[String(FWbemObject.ErrorCleared)]));// Boolean
    Writeln(Format('ErrorCorrectType               %d',[Integer(FWbemObject.ErrorCorrectType)]));// Uint16
    Writeln(Format('ErrorData                      %d',[Integer(FWbemObject.ErrorData)]));// Uint8
    Writeln(Format('ErrorDataOrder                 %d',[Integer(FWbemObject.ErrorDataOrder)]));// Uint16
    Writeln(Format('ErrorDescription               %s',[String(FWbemObject.ErrorDescription)]));// String
    Writeln(Format('ErrorInfo                      %d',[Integer(FWbemObject.ErrorInfo)]));// Uint16
    Writeln(Format('ErrorMethodology               %s',[String(FWbemObject.ErrorMethodology)]));// String
    Writeln(Format('ErrorResolution                %d',[Integer(FWbemObject.ErrorResolution)]));// Uint64
    Writeln(Format('ErrorTime                      %s',[String(FWbemObject.ErrorTime)]));// Datetime
    Writeln(Format('ErrorTransferSize              %d',[Integer(FWbemObject.ErrorTransferSize)]));// Uint32
    Writeln(Format('FlushTimer                     %d',[Integer(FWbemObject.FlushTimer)]));// Uint32
    Writeln(Format('InstallDate                    %s',[String(FWbemObject.InstallDate)]));// Datetime
    Writeln(Format('InstalledSize                  %d',[Integer(FWbemObject.InstalledSize)]));// Uint32
    Writeln(Format('LastErrorCode                  %d',[Integer(FWbemObject.LastErrorCode)]));// Uint32
    Writeln(Format('Level                          %d',[Integer(FWbemObject.Level)]));// Uint16
    Writeln(Format('LineSize                       %d',[Integer(FWbemObject.LineSize)]));// Uint32
    Writeln(Format('Location                       %d',[Integer(FWbemObject.Location)]));// Uint16
    Writeln(Format('MaxCacheSize                   %d',[Integer(FWbemObject.MaxCacheSize)]));// Uint32
    Writeln(Format('Name                           %s',[String(FWbemObject.Name)]));// String
    Writeln(Format('NumberOfBlocks                 %d',[Integer(FWbemObject.NumberOfBlocks)]));// Uint64
    Writeln(Format('OtherErrorDescription          %s',[String(FWbemObject.OtherErrorDescription)]));// String
    Writeln(Format('PNPDeviceID                    %s',[String(FWbemObject.PNPDeviceID)]));// String
    Writeln(Format('PowerManagementCapabilities    %d',[Integer(FWbemObject.PowerManagementCapabilities)]));// Uint16
    Writeln(Format('PowerManagementSupported       %s',[String(FWbemObject.PowerManagementSupported)]));// Boolean
    Writeln(Format('Purpose                        %s',[String(FWbemObject.Purpose)]));// String
    Writeln(Format('ReadPolicy                     %d',[Integer(FWbemObject.ReadPolicy)]));// Uint16
    Writeln(Format('ReplacementPolicy              %d',[Integer(FWbemObject.ReplacementPolicy)]));// Uint16
    Writeln(Format('StartingAddress                %d',[Integer(FWbemObject.StartingAddress)]));// Uint64
    Writeln(Format('Status                         %s',[String(FWbemObject.Status)]));// String
    Writeln(Format('StatusInfo                     %d',[Integer(FWbemObject.StatusInfo)]));// Uint16
    Writeln(Format('SupportedSRAM                  %d',[Integer(FWbemObject.SupportedSRAM)]));// Uint16
    Writeln(Format('SystemCreationClassName        %s',[String(FWbemObject.SystemCreationClassName)]));// String
    Writeln(Format('SystemLevelAddress             %s',[String(FWbemObject.SystemLevelAddress)]));// Boolean
    Writeln(Format('SystemName                     %s',[String(FWbemObject.SystemName)]));// String
    Writeln(Format('WritePolicy                    %d',[Integer(FWbemObject.WritePolicy)]));// Uint16
  
    Writeln('');
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_CacheMemoryInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;   
end.
How to Get Cache Memory Information in Delphi

Post a Comment