Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to wait the whole child process?

I have problem on how to wait the whole child process. I have problem on waiting child process while run an installation process. For example I have installation files (setup.exe and test.msi). The setup process is needed to check the installer prerequisites. So I create process for the setup.exe file. The problem is appear when the setup.exe is finish checking the prerequisites and run the test.msi

When the setup.exe start running the test.msi, the test.msi process become independent new process of setup.exe and the setup.exe process is closed right after running the test.msi

What I need is to wait the whole process including the test.msi process is done, Is there any way to watch the new process generated by the child of main process (in this case is process that started by setup.exe)

Here my code:
[code]
function TInstallProcess.ExecuteAndWait(filename,workdir: string;
visibility: Integer): Cardinal;
var
appName: array[0..512] of char;
currDir: array[0..255] of char;
startInfo: TStartupInfo;
procInfo: TProcessInformation;
begin
StrPCopy(appName, filename);
StrPCopy(currDir, workDir);

FillChar(startInfo, Sizeof(startInfo), #0);
startInfo.cb := Sizeof(startInfo);
startInfo.dwFlags := STARTF_USESHOWWINDOW;
startInfo.wShowWindow := visibility;

if (not CreateProcess(nil, appName, nil, nil, false, (CREATE_NEW_PROCESS_GROUP +
NORMAL_PRIORITY_CLASS), nil, currDir, startInfo, procInfo)) then
Result := $FFFFFFFF
else
begin
WaitForSingleObject(procInfo.hProcess, INFINITE);
GetExitCodeProcess(procInfo.hProcess, Result);
CloseHandle(procInfo.hProcess);
CloseHandle(procInfo.hThread);
end;
end;
[/code]

Thanks.
Sign In or Register to comment.