Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have the Process ID and need to close the associate process programmatically with Delphi 5

Tags:

delphi

Can anyone help me with a coding example to close the associated process when I have the Process ID. I will be using Delphi 5 to perform this operation programmatically on a Windows 2003 server.

like image 685
JR. Avatar asked Dec 05 '22 03:12

JR.


1 Answers

If you have a process id and want to force that process to terminate, you can use this code:

function TerminateProcessByID(ProcessID: Cardinal): Boolean;
var
  hProcess : THandle;
begin
  Result := False;
  hProcess := OpenProcess(PROCESS_TERMINATE,False,ProcessID);
  if hProcess > 0 then
  try
    Result := Win32Check(Windows.TerminateProcess(hProcess,0));
  finally
    CloseHandle(hProcess);
  end;
end;
like image 109
vcldeveloper Avatar answered May 20 '23 17:05

vcldeveloper