Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#14

AW: WMI Speicherfresser wie beseitiegen

  Alt 21. Okt 2016, 22:01
Delphi-Quellcode:
// This code was generated by the Wmi Delphi Code Creator http://theroadtodelphi.wordpress.com
// Version: 1.8.3.0
// LIABILITY DISCLAIMER
// THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
// YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
// DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.

program GetWMI_Info;

{$APPTYPE CONSOLE}

uses
(*  SysUtils, ActiveX, ComObj, Variants;  *)
  Winapi.Windows,
  System.SysUtils,
  Winapi.ActiveX,
  System.Win.ComObj,
  System.Variants;

function VarToInt(const AVariant: Variant): INT64;
begin Result := StrToIntDef(Trim(VarToStr(AVariant)), 0); end;

// "CIM_MemoryCapacity" beschreibt den Speichertyp, der auf einem physikalischen
// Element installiert werden kann, und seine minimale/maximale Konfiguration.
// Instanzen der Klasse "CIM_PhysicalMemory" enthalten Informationen über die
// Speicherposition und die minimalen/maximalen Anforderungen.

procedure GetCIM_MemoryCapacityInfo;
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 CIM_MemoryCapacity','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('MaximumMemoryCapacity %d',[VarToInt(FWbemObject.MaximumMemoryCapacity)]));// Uint64
    Writeln(Format('MemoryType %d',[VarToInt(FWbemObject.MemoryType)]));// Uint16
    Writeln(Format('MinimumMemoryCapacity %d',[VarToInt(FWbemObject.MinimumMemoryCapacity)]));// Uint64
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
       
    Writeln('');
    FWbemObject:=Unassigned;
  end;
end;

procedure GetCIM_PhysicalMemoryInfo;
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 CIM_PhysicalMemory','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('BankLabel %s',[VarToStr(FWbemObject.BankLabel)]));// String
    Writeln(Format('Capacity %d',[VarToInt(FWbemObject.Capacity)]));// Uint64
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String
    Writeln(Format('CreationClassName %s',[VarToStr(FWbemObject.CreationClassName)]));// String
    Writeln(Format('DataWidth %d',[VarToInt(FWbemObject.DataWidth)]));// Uint16
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('FormFactor %d',[VarToInt(FWbemObject.FormFactor)]));// Uint16
    Writeln(Format('HotSwappable %s',[VarToStr(FWbemObject.HotSwappable)]));// Boolean
    Writeln(Format('InstallDate %s',[VarToStr(FWbemObject.InstallDate)]));// Datetime
    Writeln(Format('InterleavePosition %d',[VarToInt(FWbemObject.InterleavePosition)]));// Uint32
    Writeln(Format('Manufacturer %s',[VarToStr(FWbemObject.Manufacturer)]));// String
    Writeln(Format('MemoryType %d',[VarToInt(FWbemObject.MemoryType)]));// Uint16
    Writeln(Format('Model %s',[VarToStr(FWbemObject.Model)]));// String
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
    Writeln(Format('OtherIdentifyingInfo %s',[VarToStr(FWbemObject.OtherIdentifyingInfo)]));// String
    Writeln(Format('PartNumber %s',[VarToStr(FWbemObject.PartNumber)]));// String
    Writeln(Format('PositionInRow %d',[VarToInt(FWbemObject.PositionInRow)]));// Uint32
    Writeln(Format('PoweredOn %s',[VarToStr(FWbemObject.PoweredOn)]));// Boolean
    Writeln(Format('Removable %s',[VarToStr(FWbemObject.Removable)]));// Boolean
    Writeln(Format('Replaceable %s',[VarToStr(FWbemObject.Replaceable)]));// Boolean
    Writeln(Format('SerialNumber %s',[VarToStr(FWbemObject.SerialNumber)]));// String
    Writeln(Format('SKU %s',[VarToStr(FWbemObject.SKU)]));// String
    Writeln(Format('Speed %d',[VarToInt(FWbemObject.Speed)]));// Uint32
    Writeln(Format('Status %s',[VarToStr(FWbemObject.Status)]));// String
    Writeln(Format('Tag %s',[VarToStr(FWbemObject.Tag)]));// String
    Writeln(Format('TotalWidth %d',[VarToInt(FWbemObject.TotalWidth)]));// Uint16
    Writeln(Format('Version %s',[VarToStr(FWbemObject.Version)]));// String

    Writeln('');
    FWbemObject:=Unassigned;
  end;
end;

procedure GetWin32_PerfRawData_PerfOS_MemoryInfo;
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_PerfRawData_PerfOS_Memory','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('AvailableBytes %d',[VarToInt(FWbemObject.AvailableBytes)]));// Uint64
    Writeln(Format('AvailableKBytes %d',[VarToInt(FWbemObject.AvailableKBytes)]));// Uint64
    Writeln(Format('AvailableMBytes %d',[VarToInt(FWbemObject.AvailableMBytes)]));// Uint64
    Writeln(Format('CacheBytes %d',[VarToInt(FWbemObject.CacheBytes)]));// Uint64
    Writeln(Format('CacheBytesPeak %d',[VarToInt(FWbemObject.CacheBytesPeak)]));// Uint64
    Writeln(Format('CacheFaultsPersec %d',[VarToInt(FWbemObject.CacheFaultsPersec)]));// Uint32
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String
    Writeln(Format('CommitLimit %d',[VarToInt(FWbemObject.CommitLimit)]));// Uint64
    Writeln(Format('CommittedBytes %d',[VarToInt(FWbemObject.CommittedBytes)]));// Uint64
    Writeln(Format('DemandZeroFaultsPersec %d',[VarToInt(FWbemObject.DemandZeroFaultsPersec)]));// Uint32
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('FreeAndZeroPageListBytes %d',[VarToInt(FWbemObject.FreeAndZeroPageListBytes)]));// Uint64
    Writeln(Format('FreeSystemPageTableEntries %d',[VarToInt(FWbemObject.FreeSystemPageTableEntries)]));// Uint32
    Writeln(Format('Frequency_Object %d',[VarToInt(FWbemObject.Frequency_Object)]));// Uint64
    Writeln(Format('Frequency_PerfTime %d',[VarToInt(FWbemObject.Frequency_PerfTime)]));// Uint64
    Writeln(Format('Frequency_Sys100NS %d',[VarToInt(FWbemObject.Frequency_Sys100NS)]));// Uint64
    Writeln(Format('LongTermAverageStandbyCacheLifetimes %d',[VarToInt(FWbemObject.LongTermAverageStandbyCacheLifetimes)]));// Uint32
    Writeln(Format('ModifiedPageListBytes %d',[VarToInt(FWbemObject.ModifiedPageListBytes)]));// Uint64
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
    Writeln(Format('PageFaultsPersec %d',[VarToInt(FWbemObject.PageFaultsPersec)]));// Uint32
    Writeln(Format('PageReadsPersec %d',[VarToInt(FWbemObject.PageReadsPersec)]));// Uint32
    Writeln(Format('PagesInputPersec %d',[VarToInt(FWbemObject.PagesInputPersec)]));// Uint32
    Writeln(Format('PagesOutputPersec %d',[VarToInt(FWbemObject.PagesOutputPersec)]));// Uint32
    Writeln(Format('PagesPersec %d',[VarToInt(FWbemObject.PagesPersec)]));// Uint32
    Writeln(Format('PageWritesPersec %d',[VarToInt(FWbemObject.PageWritesPersec)]));// Uint32
    Writeln(Format('PercentCommittedBytesInUse %d',[VarToInt(FWbemObject.PercentCommittedBytesInUse)]));// Uint32
    Writeln(Format('PercentCommittedBytesInUse_Base %d',[VarToInt(FWbemObject.PercentCommittedBytesInUse_Base)]));// Uint32
    Writeln(Format('PoolNonpagedAllocs %d',[VarToInt(FWbemObject.PoolNonpagedAllocs)]));// Uint32
    Writeln(Format('PoolNonpagedBytes %d',[VarToInt(FWbemObject.PoolNonpagedBytes)]));// Uint64
    Writeln(Format('PoolPagedAllocs %d',[VarToInt(FWbemObject.PoolPagedAllocs)]));// Uint32
    Writeln(Format('PoolPagedBytes %d',[VarToInt(FWbemObject.PoolPagedBytes)]));// Uint64
    Writeln(Format('PoolPagedResidentBytes %d',[VarToInt(FWbemObject.PoolPagedResidentBytes)]));// Uint64
    Writeln(Format('StandbyCacheCoreBytes %d',[VarToInt(FWbemObject.StandbyCacheCoreBytes)]));// Uint64
    Writeln(Format('StandbyCacheNormalPriorityBytes %d',[VarToInt(FWbemObject.StandbyCacheNormalPriorityBytes)]));// Uint64
    Writeln(Format('StandbyCacheReserveBytes %d',[VarToInt(FWbemObject.StandbyCacheReserveBytes)]));// Uint64
    Writeln(Format('SystemCacheResidentBytes %d',[VarToInt(FWbemObject.SystemCacheResidentBytes)]));// Uint64
    Writeln(Format('SystemCodeResidentBytes %d',[VarToInt(FWbemObject.SystemCodeResidentBytes)]));// Uint64
    Writeln(Format('SystemCodeTotalBytes %d',[VarToInt(FWbemObject.SystemCodeTotalBytes)]));// Uint64
    Writeln(Format('SystemDriverResidentBytes %d',[VarToInt(FWbemObject.SystemDriverResidentBytes)]));// Uint64
    Writeln(Format('SystemDriverTotalBytes %d',[VarToInt(FWbemObject.SystemDriverTotalBytes)]));// Uint64
    Writeln(Format('Timestamp_Object %d',[VarToInt(FWbemObject.Timestamp_Object)]));// Uint64
    Writeln(Format('Timestamp_PerfTime %d',[VarToInt(FWbemObject.Timestamp_PerfTime)]));// Uint64
    Writeln(Format('Timestamp_Sys100NS %d',[VarToInt(FWbemObject.Timestamp_Sys100NS)]));// Uint64
    Writeln(Format('TransitionFaultsPersec %d',[VarToInt(FWbemObject.TransitionFaultsPersec)]));// Uint32
    Writeln(Format('TransitionPagesRePurposedPersec %d',[VarToInt(FWbemObject.TransitionPagesRePurposedPersec)]));// Uint32
    Writeln(Format('WriteCopiesPersec %d',[VarToInt(FWbemObject.WriteCopiesPersec)]));// Uint32

    Writeln('');
    FWbemObject:=Unassigned;
  end;
end;
//------------------------------------------------------------------------------
var
  memory: TMemoryStatusEx;
begin
ReportMemoryLeaksOnShutdown := True;
  memory.dwLength := SizeOf(memory);
  GlobalMemoryStatusEx(memory);
  WriteLn('Total memory: ' + IntToStr(memory.ullTotalPhys) + ' Bytes');
  WriteLn('Available memory: ' + IntToStr(memory.ullAvailPhys) + ' Bytes');

try
    CoInitialize(nil);
    try
      GetCIM_MemoryCapacityInfo;
  WriteLn('---------------------------------------------------------------');
      GetCIM_PhysicalMemoryInfo;
  WriteLn('---------------------------------------------------------------');
      GetWin32_PerfRawData_PerfOS_MemoryInfo;
    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.
  Mit Zitat antworten Zitat