1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
BOOL RunProgram(CString commandLine, BOOL wait, DWORD& exitCode)
{
BOOL ret;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
CString strHelpPath;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
memset(&processInfo, 0, sizeof(processInfo));
ret = ::CreateProcess(
NULL,
(LPTSTR) (LPCTSTR) commandLine,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&processInfo);
if (ret)
{
if (wait)
{
while (::WaitForSingleObject(processInfo.hProcess, 100) == WAIT_TIMEOUT)
ProcessMessages();
::GetExitCodeProcess(processInfo.hProcess, &exitCode);
}
::CloseHandle(processInfo.hProcess);
::CloseHandle(processInfo.hThread);
}
return ret;
}
|