uses
TLHelp32,PsAPI;
(1)显示进程列表:
1 procedure TForm1.Button2Click(Sender: TObject); 2 var 3 lppe: TProcessEntry32; 4 found : boolean; 5 Hand : THandle; 6 P:DWORD; 7 s:string; 8 begin 9 ListBox1.Items.Clear ; 10 Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); 11 found := Process32First(Hand,lppe); 12 while found do 13 begin 14 s := StrPas(lppe.szExeFile); 15 if lppe.th32ProcessID>0 then 16 p := lppe.th32ProcessID 17 else 18 p := 0; 19 ListBox1.Items.AddObject(s,pointer(p));//列出所有进程。 20 found := Process32Next(Hand,lppe); 21 end; 22 end;
(2)杀死某进程:
1 procedure TForm1.Button3Click(Sender: TObject); 2 var 3 lppe: TProcessEntry32; 4 found : boolean; 5 Hand : THandle; 6 P:DWORD; 7 sExeFile,sSelect:string; 8 killed:boolean; 9 begin 10 p :=DWORD(ListBox1.Items.Objects[ListBox1.itemindex]); 11 if P<>0 then