uses TLHelp32;
procedure KillTask(ExeFileName: string; nur1: boolean);
var
FProcessEntry32: TProcessEntry32;
FSnapshotHandle: THandle;
Loop: Bool;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
Loop := Process32First(FSnapshotHandle, FProcessEntry32);
while Loop do begin
if ((AnsiUpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
AnsiUpperCase(ExeFileName))
or (AnsiUpperCase(FProcessEntry32.szExeFile) =
AnsiUpperCase(ExeFileName))) then begin
TerminateProcess(
OpenProcess(1, false, FProcessEntry32.th32ProcessID), 0);
if nur1 then break;
end;
Loop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
KillTask('notepad.exe', false);
end;