DVDavy
DVDavy

Reputation: 79

How do I get a list of running processes remotely?

How do i get list of the running processes on some other machine (over the network) using Delphi?

Upvotes: 1

Views: 2273

Answers (2)

Stijn Sanders
Stijn Sanders

Reputation: 36840

See the EnumProcesses procedure from the TlHelp32 unit.

Upvotes: 0

RRUZ
RRUZ

Reputation: 136391

You can use the Win32_Process WMI Class.

Check this sample

{$APPTYPE CONSOLE}
uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;


procedure  GetWin32_ProcessInfo;
const
  WbemUser            ='';//set the user name to log in
  WbemPassword        ='';//set the password
  WbemComputer        ='localhost';//set the name of the remote machine or IP address
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_Process','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('Name         %s',[String(FWbemObject.Name)]));// String
    Writeln(Format('ProcessId    %d',[Integer(FWbemObject.ProcessId)]));// Uint32
    Writeln;
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_ProcessInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.

In order to work with the WMI in a remote machine you must set the firewall and DCOM settings check these articles for more info .

Upvotes: 11

Related Questions