unit Unit1; interface uses Windows,Tlhelp32, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, psapi; type TForm1 = class(TForm) ListView1: TListView; Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: 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); var found:boolean; //定义枚举进程所需变量 NewItem: TListItem; FSnapshotHandle:tHANDLE; lppe:TProcessEntry32; begin
with listview1 do begin Columns.Add; Columns.Add; Columns.Add; ViewStyle:=vsreport; GridLines:=true; columns.items[0].caption:='映像名称';
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);//进程名称