得到系统进程和路径unit Unit1;interfaceusesWindows,Tlhelp32, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ComCtrls, psapi;typeTForm1 = class(TForm) ListView1: TListView; Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject);private { Private declarations }public { Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}function GetProcessPath(ProcessID: DWORD): string;var Hand: THandle; ModName: Array[0..Max_Path-1] of Char; hMod: HModule; n: DWORD;begin Result:=''; Hand:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID); if Hand>0 then try ENumProcessModules(Hand,@hMod,Sizeof(hMod),n); if GetModuleFileNameEx(Hand,hMod,ModName,Sizeof(ModName))>0 then // Result:=ExtractFilePath(ModName);//得到路径 Result:=ModName; //得到路径和文见名 except end;end;procedure TForm1.Button1Click(Sender: TObject);varfound:boolean; //定义枚举进程所需变量NewItem: TListItem;FSnapshotHandle:tHANDLE;lppe:TProcessEntry32;beginwith listview1 dobeginColumns.Add;Columns.Add;Columns.Add;ViewStyle:=vsreport;GridLines:=true;columns.items[0].caption:='映像名称';columns.items[1].caption:='进程ID';columns.items[2].caption:='映像路径';Columns.Items[0].Width:=100;Columns.Items[1].Width:=50; //初始化listviewColumns.Items[2].Width:=300;end;ListView1.Items.BeginUpdate;ListView1.Items.Clear;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照lppe.dwSize := Sizeof(lppe); //初始化found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信while found do begin NewItem := ListView1.Items.Add; //在ListView1显示 NewItem.ImageIndex := -1; NewItem.Caption := ExtractFileName(lppe.szExeFile);//进程名称 NewItem.subItems.Add(IntToStr(lppe.th32ProcessID));//进程ID NewItem.subItems.Add(GetProcessPath(lppe.th32ProcessID)); found := Process32Next(FSnapshotHandle, lppe);end;CloseHandle(FSnapshotHandle);ListView1.Items.EndUpdate;self.Label1.Caption:='当前系统共有'+''+inttostr(listview1.Items.count)+''+'个进程 ' ;end;end.