DWORD dwExitCode;
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
GetStartupInfo( &si );
BOOL bSuccess = CreateProcess( NULL,
(LPTSTR)commandLine.c_str(),
&sa,
NULL,
FALSE,
CREATE_NO_WINDOW | CREATE_DEFAULT_ERROR_MODE |
ABOVE_NORMAL_PRIORITY_CLASS, // creation flags
NULL,
currentDir,
&si,
&pi );
where commandLine and currentDir have been set to the appropriate
values.
I then use the following code:
DWORD dwSuccess = WaitForSingleObject(pi.hProcess, INFINITE);
// Retcode of application
bSuccess = GetExitCodeProcess( pi.hProcess, &dwExitCode );
if ( dwSuccess != WAIT_OBJECT_0 )
{
bSuccess = FALSE;
LPVOID lpMsgBuf;
::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwSuccess,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
msg = "InstallServices::launchApp() - Unknown Error : ";
msg += (LPCTSTR)lpMsgBuf;
theTRACER->log(ExceptionTraces, msg.c_str());
// Free the buffer.
LocalFree( lpMsgBuf );
}
This is required in the case where the child process has not killed
the parent process, so that the parent process knows when the child
process has completed. However, in the case where the child process
does need to kill the parent process, the WaitForSingleObject seems to
be preventing the child from doing so.
Any ideas?