// -----------------------------------------------------------------------------
// ADsEnumerateNext
// -----------------------------------------------------------------------------
function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
var pvar: OleVARIANT;
var pcElementsFetched: ULONG): HRESULT;
safecall;
external '
activeds.dll';
// -----------------------------------------------------------------------------
// TProcessList.DumpWMI_Process
// -----------------------------------------------------------------------------
procedure TProcessList.DumpWMI_Process(Process: SWBemObject);
var
Enum: IEnumVARIANT;
varArr: OleVariant;
lNumElements: ULong;
SProp: ISWbemProperty;
Prop: OleVariant;
oProcess: TProcess;
oProcessInfo: TProcessInfo;
begin
oProcess := TProcess.Create;
oProcess.FName := '
+ WMI Path: ' + Process.Path_.Path;
Enum := Process.Properties_._NewEnum
as IEnumVariant;
Process.
while (Succeeded(ADsEnumerateNext(Enum, 1, VarArr, lNumElements)))
and
(lNumElements > 0)
do
begin
if Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty, SProp))
and
Assigned(SProp)
then
begin
try
oProcessInfo := TProcessInfo.Create;
oProcessInfo.ProprtyName := SProp.
Name;
Prop := SProp.Get_Value;
oProcessInfo.PropertyType := VarTypeAsText(VarType(Prop));
oProcessInfo.PropertyValue := VarToStr(Prop);
oProcess.FProcessInfoList.Add(oProcessInfo);
if SProp.
Name = '
Caption'
then
sListAll := sListAll + oProcessInfo.PropertyValue + #13#10;
except
on E:
Exception do
begin
end;
end;
end;
end;
Add(oProcess);
end;
// TProcessList.DumpWMI_Process
// -----------------------------------------------------------------------------
// TProcessList.GetProcesses
// -----------------------------------------------------------------------------
procedure TProcessList.GetProcesses;
var
Server:
string;
Enum: IEnumVARIANT;
varArr: OleVariant;
lNumElements: ULong;
AName:
array[0..255]
of Char;
ASize: DWORD;
begin
Clear;
sListAll := '
';
if (ParamCount = 0)
then
begin
Server := '
';
ASize := SizeOf(AName) - 1;
if GetComputerName(@AName, ASize)
then Server := AName;
end
else
begin
Server := ParamStr(1);
end;
Enum := CoSWbemLocator.Create.ConnectServer(Server, '
root\cimv2', '
',
'
', '
', '
', 0,
nil).ExecQuery('
Select * from Win32_Process', '
WQL',
wbemFlagBidirectional,
nil)._NewEnum
as IEnumVariant;
while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements)))
and
(lNumElements > 0)
do
begin
DumpWMI_Process(IUnknown(varArr)
as SWBemObject);
end;
end;
// TProcessList.GetProcesses