unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WbemScripting_TLB,
ActiveX, StdCtrls, ExtCtrls;
Type
TForm1 =
class(TForm)
Memo1: TMemo;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function getWMIProcess : TStringList;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.getWMIProcess : TStringList;
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
result := TStringList.Create;
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;
result.add(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
Memo1.Lines := getWMIProcess;
end;
end.