试试下面的吧。[
]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
TLHelp32,Controls, Forms, Dialogs, StdCtrls;
type
TProcessInfo = Record
ExeFile : String;
ProcessID : DWORD;
end;
pProcessInfo = ^TProcessInfo;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var p : pProcessInfo;
ContinueLoop:BOOL;
var
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
begin
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;
Memo1.lines.Add(Format('进程ID号:%d 文件名:%s',[p.ProcessID,p.ExeFile]) );
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;
end.