1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| unit KillProc;
interface
uses
Windows, SysUtils, TlHelp32;
function KillProcess(const ProcessName : string; All : boolean = False) : boolean;
implementation
function KillProcess(const ProcessName : string; All : boolean = False) : boolean;
var ProcessEntry32 : TProcessEntry32;
HSnapShot : THandle;
HProcess : THandle;
const ProcessName = 'iexplore.exe';
begin
Result := False;
HSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if HSnapShot = 0 then exit;
ProcessEntry32.dwSize := sizeof(ProcessEntry32);
if Process32First(HSnapShot, ProcessEntry32) then
repeat
if CompareText(ProcessEntry32.szExeFile, ProcessName) = 0 then
begin
HProcess := OpenProcess(PROCESS_TERMINATE, False, ProcessEntry32.th32ProcessID);
if HProcess <> 0 then
begin
Result := TerminateProcess(HProcess, 0) or Result;
CloseHandle(HProcess);
end;
if not All then Break;
end;
until not Process32Next(HSnapShot, ProcessEntry32);
CloseHandle(HSnapshot);
end;
end. |
Partager