was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

49 Visitors Online


 
...Informationen über einen Prozess mittels WMI erhalten?
Autor: experts-exchange
[ Tip ausdrucken ]  

Tip Bewertung (49):  
     




uses
  
ActiveX, WbemScripting_TLB;

function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
  var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecallexternal 'activeds.dll';

procedure DumpWMI_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('+ WMI Path: ' + Process.Path_.Path);
  Enum := Process.Properties_._NewEnum as IEnumVariant;
  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
        
PropName  := SProp.Name;
        Prop := SProp.Get_Value;
        PropType := VarTypeAsText(VarType(Prop));
        PropValue := VarToStr(Prop);
        Form1.Memo1.Lines.Add('  + ' + PropName + '[' + PropType + '] = ' + PropValue);
      except
        on 
E: Exception do
        begin
          
// WriteLn(ErrOutput, PropName, ': ', E.Message);
        
end;
      end;
    end;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
  
Server: string;
  Enum: IEnumVARIANT;
  varArr: OleVariant;
  lNumElements: ULong;
  AName: array[0..255] of Char;
  ASize: DWORD;
begin
  if 
(ParamCount = 0) then
  begin
    
Server := '';
    ASize  := SizeOf(AName) - 1;
    if GetComputerName(@AName, ASize) then Server := AName;
  end
  else
  begin
    
Server := ParamStr(1);
  end;
  try
    
Memo1.Lines.BeginUpdate;
    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;
  finally
    
Memo1.Lines.EndUpdate;
  end;
end;

{
 You need the WbemScripting_TLB unit, which you can create by installing the type library
 <Windows System32>\wbem\wbemdisp.tlb type library using the "Project|Import type library" menu option.
}


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners