这是其核心,源程序可以到http://www.playicq.com/dispdoc.php?t=&id=2725下载
procedure TForm1.FormShow(Sender: TObject);
var
Lppe: TProcessEntry32;
Found: boolean;
Handle: THandle;
s:string;
begin
ListBox1.clear;
//设定快照集的名柄
Handle:= CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
//找到第一个进程
lppe.dwSize:=Sizeof(TProcessEntry32); //这一行非常重要
Found:= Process32First(Handle,Lppe);
while Found do
begin
s:=Lppe.szExeFile;
ListBox1.items.Add(s);
//继续找下一个进程
Found:= Process32Next(Handle,Lppe);
end;
end;
procedure TForm1.suiButton1Click(Sender: TObject);
var
Found: BOOL;
HSnapshot, HProcess: THandle;
Lppe: TProcessEntry32;
begin
HSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Lppe.dwSize:=Sizeof(Lppe);
Found:=Process32First(HSnapshot,Lppe);
while Found do
begin
try
if Lppe.szExeFile=ListBox1.Items.Strings[ListBox1.itemindex] then
begin
HProcess:=OpenProcess(PROCESS_ALL_ACCESS, FALSE, Lppe.th32ProcessID);
//终止进程
TerminateProcess(HProcess,0);
ListBox1.Items.Delete(ListBox1.itemindex);
exit;
end;
except end;
Found:=Process32Next(HSnapshot,Lppe);
end;
end;