场景:
我需要从App1中执行App2并传递App1.Handle作为参数。
App2应该等待App1关闭后再继续执行。在此之后,App2应替换App1.exe文件为已更新的版本。
- 是否有更好的方法来更新正在运行的可执行文件?
- 如果没有……在App2中,我知道App1.Handle,我应该如何检查App1是否已经关闭?从App1.Handle开始如何验证?
编辑:
App1:
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;
应用2:
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;