-------------------------------------------------------------------------
| 82 | |
| 83 | //------------------------------------------------------------------------- |
| 84 | void Process::Start(DWORD creationFlags) |
| 85 | { |
| 86 | if (processInformation_) |
| 87 | THROW(L"Process already started"); |
| 88 | |
| 89 | STARTUPINFO lpStartupInfo; |
| 90 | |
| 91 | ZeroMemory(&lpStartupInfo, sizeof(lpStartupInfo)); |
| 92 | const auto* workindDirectory = startInfo_.GetWorkingDirectory(); |
| 93 | auto optionalCommandLine = CreateCommandLine(startInfo_.GetArguments()); |
| 94 | auto commandLine = (optionalCommandLine) ? &(*optionalCommandLine)[0] : nullptr; |
| 95 | |
| 96 | processInformation_ = PROCESS_INFORMATION{}; |
| 97 | if (!CreateProcess( |
| 98 | nullptr, |
| 99 | commandLine, |
| 100 | nullptr, |
| 101 | nullptr, |
| 102 | FALSE, |
| 103 | creationFlags, |
| 104 | nullptr, |
| 105 | (workindDirectory) ? workindDirectory->c_str() : nullptr, |
| 106 | &lpStartupInfo, |
| 107 | &processInformation_.get() |
| 108 | )) |
| 109 | { |
| 110 | std::wostringstream ostr; |
| 111 | |
| 112 | if (!Tools::FileExists(startInfo_.GetPath())) |
| 113 | ostr << CannotFindPathMessage + startInfo_.GetPath().wstring(); |
| 114 | else |
| 115 | { |
| 116 | ostr |
| 117 | << CheckIfValidExecutableMessage |
| 118 | << std::endl; |
| 119 | |
| 120 | #ifndef _WIN64 |
| 121 | ostr << L"\n*** This version support only 32 bits executable " |
| 122 | L"***.\n\n"; |
| 123 | #endif |
| 124 | ostr << startInfo_ |
| 125 | << CppCoverage::GetErrorMessage(GetLastError()); |
| 126 | } |
| 127 | throw std::runtime_error(Tools::ToLocalString(ostr.str())); |
| 128 | } |
| 129 | } |
| 130 | } |