uses
ActiveX,WbemScripting_TLB;
functionADsEnumerateNext(pEnumVariant:IEnumVARIANT;cElements:ULONG;
varpvar:OleVARIANT;varpcElementsFetched:ULONG):HRESULT;safecall;external'activeds.dll';
procedureDumpWMI_Process(Process:SWBemObject);
var
Enum:IEnumVARIANT;
varArr:OleVariant;
lNumElements:ULong;
SProp:ISWbemProperty;
Prop:OleVariant;
PropName:string;
PropType:string;
PropValue:string;
begin
Form1.Memo1.Lines.Add('+WMIPath:'+Process.Path_.Path);
Enum:=Process.Properties_._NewEnumasIEnumVariant;
while(Succeeded(ADsEnumerateNext(Enum,1,VarArr,lNumElements)))and
(lNumElements>0)do
begin
ifSucceeded(IDispatch(varArr).QueryInterface(SWBemProperty,SProp))and
Assigned(SProp)then
begin
try
PropName:=SProp.Name;
Prop:=SProp.Get_Value;
PropType:=VarTypeAsText(VarType(Prop));
PropValue:=VarToStr(Prop);
Form1.Memo1.Lines.Add('+'+PropName+'['+PropType+']='+PropValue);
except
onE:Exceptiondo
begin
//WriteLn(ErrOutput,PropName,':',E.Message);
end;
end;
end;
end;
end;
procedureTForm1.Button1Click(Sender:TObject);
var
Server:string;
Enum:IEnumVARIANT;
varArr:OleVariant;
lNumElements:ULong;
AName:array[0..255]ofChar;
ASize:DWORD;
begin
if(ParamCount=0)then
begin
Server:='';
ASize:=SizeOf(AName)-1;
ifGetComputerName(@AName,ASize)thenServer:=AName;
end
else
begin
Server:=ParamStr(1);
end;
try
Memo1.Lines.BeginUpdate;
Enum:=CoSWbemLocator.Create.ConnectServer(Server,'root\cimv2','',
'','','',0,nil).ExecQuery('Select*fromWin32_Process','WQL',
wbemFlagBidirectional,nil)._NewEnumasIEnumVariant;
while(Succeeded(ADsEnumerateNext(Enum,1,varArr,lNumElements)))and
(lNumElements>0)do
begin
DumpWMI_Process(IUnknown(varArr)asSWBemObject);
end;
finally
Memo1.Lines.EndUpdate;
end;
end;
{
YouneedtheWbemScripting_TLBunit,whichyoucancreatebyinstallingthetypelibrary
<WindowsSystem32>\wbem\wbemdisp.tlbtypelibraryusingthe"Project|Importtypelibrary"menuoption.
}
Get Information about a Process using WMI?【转】
最新推荐文章于 2022-02-28 06:37:38 发布
本文介绍了一个使用 Delphi 枚举 Windows 管理规范 (WMI) 中进程的方法。通过 Delphi 代码示例展示了如何连接到 WMI 服务,并执行查询来获取系统中运行的所有进程的信息。
9857

被折叠的 条评论
为什么被折叠?



