Scenario: From App1, I need to execute App2 passing App1.Handle as param. App2 should wait until App1's close. After this, App2 should replace App1.exe file with an updated version.
- Are there better ways to update a running executable file?
- If there aren't.. In App2, I know App1.Handle and I should check if App1 has been closed. How can this be verified starting from App1.Handle?
var ProcessHandle : THandle; begin ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, GetCurrentProcessId()); //Is PROCESS_ALL_ACCESS needed? ShellExecute(0, 'open', 'App2.exe', PChar(IntToStr(ProcessHandle)), '.\', SW_SHOW); end;
var SenderHandle : THandle; begin if(ParamStr(1) <> '') then begin SenderHandle := StrToInt(ParamStr(1)); WaitForSingleObject(SenderHandle, INFINITE); ShowMessage('App1 Terminated!'); //Showmessage is executed when App1 is still running, what's wrong? end; end;