Together with WM_CLOSE and WM_QUIT you can make it really elegant and just start the second instance of the application with STOP as a parameter. Like this:
In the main part of the project ...
if ((ParamCount >= 1) and (UpperCase(paramstr(1)) = 'STOP')) then
When the application starts and sees that it has the "STOP" parameter, then track down the first instance and kill it. Then close the second instance without creating the main form, etc. Thus, you do not need to write / deploy the second program, only to kill the first.
source share