分析其中的結束進程函數,原型:
以下是代碼片段:
procedure TForm1.EndProcess(AFileName: string);
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapShotHandle: THandle;
FProcessEntry32: TProcessEntry32;
KillHandle: THandle;//用於殺死進程
begin
FSnapShotHandle := CreateToolhelp32SnapShot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(AFileName)) or (UpperCase(FProcessEntry32.szExeFile )=UpperCase(AFileName))) then
begin
KillHandle := OpenProcess(PROCESS_TERMINATE, False, FProcessEntry32.th32ProcessID);
TerminateProcess(KillHandle, 0);//強制關閉進程
CloseHandle(KillHandle);
exit;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;