procedure Tsyste.procedu(); //得到当前的进程名和ID
var FSnap:Thandle;
PE:TprocessEntry32;
PPE
ProcessEntry32;
begin
if FSnap>0 then closeHandle(FSnap);
FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPALL,0);
if FSnap=-1 then
raise Exception.create('Windows发生致命错误即将关闭!');
PE.dwsize:=sizeof(PE);
if Process32first(FSnap,PE) then
repeat
New(PPE);
PPE^:=PE;
ListBox1.items.add(PPE.Th32processID)+'#'+PPE.szExeFile);
until Not Process32next(FSnap,PE);
closeHandle(FSnap);
end;
关闭的时候,找到哪个进程ID
var h,a:Thandle;
h:=openprocess(PROCESS_ALL_ACCESS,True,PPE.Th32processID);
getExitCodeProcess(h,a);
if terminateProcess(h,a) then
begin
Showmessage('进程已关闭!');
end;