AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Memory-Leak WMI

Ein Thema von El.Blindo · begonnen am 30. Jan 2007 · letzter Beitrag vom 7. Feb 2007
 
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: Memory-Leak WMI

  Alt 30. Jan 2007, 19:25
Er meint das so...

Delphi-Quellcode:
procedure TForm1.getWMIProcess(Liste:TStrings);
var
   l_WMILocator: ISWbemLocator;
   l_WMIServices: ISWbemServices;
   l_WMIObjectDefinition: ISWbemObject;
   l_WMIObjectSet: SWbemObjectSet;
   l_WMIObjectInstances: IEnumVariant;
   l_WMIObject: ISWbemObject;
   l_WMIPropertySet: ISWbemPropertySet;
   l_WMIProperty: ISWbemProperty;

   l_TempObj: OleVariant;
   l_ObjValue: Cardinal;

   WMI_Name : String;
   WMI_PID : uint64;
   WMI_Tick : uint64;
   WMI_UTime : uint64;
   WMI_KTime : uint64;
   WMI_Mem : uint64;
begin
   l_WMILocator := CoSWbemLocator.Create;
   l_WMIServices := L_WMILocator.ConnectServer('.', 'root\CIMV2', '', '', '', '', 0, nil);
   l_WMIObjectDefinition := l_WMIServices.Get('Win32_Process', wbemFlagUseAmendedQualifiers, nil);
   l_WMIObjectSet := l_WMIObjectDefinition.Instances_(0, nil);
   l_WMIObjectInstances := (l_WMIObjectSet._NewEnum) as IEnumVariant;

   while (l_WMIObjectInstances.Next(1, l_TempObj, l_ObjValue) = S_OK) do
   begin
      WMI_Tick := GetTickCount;
      l_WMIObject:= IUnknown(l_TempObj) as SWBemObject;

      l_WMIPropertySet := l_WMIObject.Properties_;

      l_WMIProperty := l_WMIPropertySet.Item('Name', 0);
      if not VarIsNull(l_WMIProperty.Get_Value) then
        WMI_Name := l_WMIProperty.Get_Value else WMI_Name := 'N/A';

      l_WMIProperty := l_WMIPropertySet.Item('ProcessId', 0);
      if not VarIsNull(l_WMIProperty.Get_Value) then
        WMI_PID := l_WMIProperty.Get_Value else WMI_PID := 0;

      l_WMIProperty := l_WMIPropertySet.Item('WorkingSetSize', 0);
      if not VarIsNull(l_WMIProperty.Get_Value) then
        WMI_Mem := l_WMIProperty.Get_Value div 1024 else WMI_Mem := 0;

      l_WMIProperty := l_WMIPropertySet.Item('UserModeTime', 0);
      if not VarIsNull(l_WMIProperty.Get_Value) then
        WMI_UTime := l_WMIProperty.Get_Value else WMI_UTime := 0;

      l_WMIProperty := l_WMIPropertySet.Item('KernelModeTime', 0);
      if not VarIsNull(l_WMIProperty.Get_Value) then
        WMI_KTime := l_WMIProperty.Get_Value else WMI_KTime := 0;

      Liste.Append(IntToStr(WMI_PID) + ' : ' + WMI_Name + ' - ' +
                   IntToStr(WMI_Mem) + ' K ' +
                   InttoStr(WMI_UTime + WMI_KTime));
   end;
   l_WMILocator := nil;
   l_WMIServices := nil;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  getWMIProcess(Memo1.Lines);
end;
Gruss
Thorsten
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:32 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