We force terminate the process by its PID.
[Terminate process by name]
1 2 3 4 5 6 |
var pid: Integer; begin pid:= 2100; processTerminate(pid); end; |
Options
pid - PID of the process
Result
True if the operation is successful, False if not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function processTerminate (pid: integer): Boolean; var hToken:THandle; hProcess:THandle; begin Result:= false; if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken ) then exit; hProcess := OpenProcess(PROCESS_TERMINATE, FALSE, pid); if hProcess = 0 then exit; if not TerminateProcess(hProcess, DWORD(-1)) then begin CloseHandle(hProcess); exit; end; CloseHandle(hProcess); Result:=true; end; |