Option 1. Send the other applicaton WM_CLOSE message. Finding the handle to applications main window may be a little tricky. FindWindow is one way.
Option 2. Start the application using CreateProcess, from which you can get the process handle (I think this is nto the handle to send a WM_CLOSE messsage to, but you could try). When you want to close the application call TerminateProcess on the process handle. This is a ugly termination that does not close DLLs that the process is using. See windows help on TerminateProcess.
Below is a function I wrote which suspends processing of the invoking application until the new process has finished. Note the freeing of resources in it.
function SHCompleteProcess(const ACommandLine:string; var AExitCode:cardinal;
AWaitInterval:dword=INFINITE):dword;
var
LProcessHandle:THandle;
StartupInfo:TStartupInfo;
ProcessInformation:TProcessInformation;
begin
{Initiate process}
FillChar(StartupInfo,Sizeof(StartupInfo),0);
FillChar(ProcessInformation,Sizeof(ProcessInformation),0);
if not CreateProcess(nil,pchar(ACommandLine),
nil,nil,false,CREATE_DEFAULT_ERROR_MODE+CREATE_NEW_CONSOLE+CREATE_NEW_PROCESS_GROUP,nil,
nil,StartupInfo,ProcessInformation)then begin
Result:=PROCESS_NOT_START;
Exit;
end;
try
{Wait for it to complete then get exit code}
LProcessHandle:=ProcessInformation.hProcess;
Result:=WaitForSingleObject(LProcessHandle,AWaitInterval);
GetExitCodeProcess(LProcessHandle,AExitCode);
finally
CloseHandle(ProcessInformation.hProcess);
CloseHandle(ProcessInformation.hThread);
end;
end;
Good luck
Simon