[SOLVED] How to kill a specific instance of a program? lazarus / 34-Windows ---------------------------------------------------------------------- Hartmut · 2018-07-24 11:34 My program (a console application) can run twice at the same time. I want the ability that the 2nd instance can kill the 1st instance. Both instances have been started by the command line (not one by each other). What I have is how to kill a process with a certain PID. To get the PID of a program I found this: http://wiki.lazarus.freepascal.org/Windows_Programming_Tips#Showing.2F finding_processes and improved it to return an array with multiple PIDs for 1 program, if multiple instances are running. My problem now is, that if 2 instances are running, then I get 2 PIDs for them and do not know which is which. So my idea is, that the 2nd instance somehow shall determine it's own PID. Then the other PID must be from instance #1 and can be killed. How can this be done? I use FPC 3.0.4 on Windows 7 32 bit. Thanks in advance. ---------------------------------------------------------------------- balazsszekely · 2018-07-24 11:41 QuoteSo my idea is, that the 2nd instance somehow shall determine it's own PID. Then the other PID must be from instance #1 and can be killed.Add windows to the uses list, then call GetCurrentProcessId function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Windows,  ....  { you can add units after this }; begin  Writeln(GetCurrentProcessId);  Readln;end. ---------------------------------------------------------------------- Hartmut · 2018-07-24 12:01 That's a perfect solution. Thank you very much for your help. ---------------------------------------------------------------------- ASerge · 2018-07-24 23:58 The System unit already has this function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE}begin  Writeln(GetProcessID);  Readln;end. ---------------------------------------------------------------------- Hartmut · 2018-07-25 16:08 Thank you ASerge for that information, which is platform independend.