Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
Delphi 7 Enterprise
|
Re: Memory-Leak WMI
30. Jan 2007, 20: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
|
|
Zitat
|