Delphi如何列举系统运行的进程

uses ... TLHelp32, ...;

 

type

  TForm1 = class(TForm)

  ...

  end;

 

var

  Form1: TForm1;

  l    : Tlist;  ////返回的东东在"L"这个TList中。

 

type

  TProcessInfo = Record

    ExeFile    : String;

    ProcessID  : DWORD;

  end;

  pProcessInfo = ^TProcessInfo;

 

implementation

 

{$R *.DFM}

 

procedure TForm1.FormCreate(Sender: TObject);

var

  p : pProcessInfo;

  i : integer;

  ContinueLoop:BOOL;

  FSnapshotHandle:THandle;

  FProcessEntry32:TProcessEntry32;

begin

  l := TList.Create;

  l.Clear;

  FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

  FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);

  ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);

  while integer(ContinueLoop)<>0 do

  begin

    New(p);

    p.ExeFile := FProcessEntry32.szExeFile;

    p.ProcessID := FProcessEntry32.th32ProcessID;

    l.Add(p);

    ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);

  end;

end

 

...

 

end.

你可能感兴趣的:(Delphi)