| 463 | #endif |
| 464 | |
| 465 | BOOL createProcess(BOOL abSkipWowChange, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation) |
| 466 | { |
| 467 | const CEStr fnDescr(L"createProcess App={", lpApplicationName, L"} Cmd={", lpCommandLine, L"}"); |
| 468 | LogFunction(fnDescr); |
| 469 | |
| 470 | MWow64Disable wow; |
| 471 | if (!abSkipWowChange) |
| 472 | wow.Disable(); |
| 473 | |
| 474 | // %PATHS% from [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths] |
| 475 | // must be already processed in IsNeedCmd >> FileExistsSearch >> SearchAppPaths |
| 476 | |
| 477 | const auto nStartTick = std::chrono::high_resolution_clock::now(); |
| 478 | |
| 479 | #if defined(SHOW_STARTED_PRINT_LITE) |
| 480 | if (gState.runMode_ == RunMode::Server) |
| 481 | { |
| 482 | _printf("Starting root: "); |
| 483 | PrintBuffer(lpCommandLine ? lpCommandLine : lpApplicationName ? lpApplicationName : L"<nullptr>"); |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | SetLastError(0); |
| 488 | |
| 489 | *lpProcessInformation = PROCESS_INFORMATION{}; |
| 490 | |
| 491 | const BOOL lbRc = CreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); |
| 492 | const DWORD dwErr = GetLastError(); |
| 493 | const auto nStartDuration = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 494 | std::chrono::high_resolution_clock::now() - nStartTick); |
| 495 | |
| 496 | wchar_t szRunRc[80]; |
| 497 | if (lbRc) |
| 498 | swprintf_c(szRunRc, L"Succeeded (%u ms) PID=%u handle=%s err=%u", static_cast<uint32_t>(nStartDuration.count()), lpProcessInformation->dwProcessId, |
| 499 | (lpProcessInformation->hProcess && lpProcessInformation->hProcess != INVALID_HANDLE_VALUE) ? L"valid" : L"null", dwErr); |
| 500 | else |
| 501 | swprintf_c(szRunRc, L"Failed (%u ms) Code=%u(x%04X)", static_cast<uint32_t>(nStartDuration.count()), dwErr, dwErr); |
| 502 | LogFunction(szRunRc); |
| 503 | |
| 504 | #if defined(SHOW_STARTED_PRINT_LITE) |
| 505 | if (gState.runMode_ == RunMode::Server) |
| 506 | { |
| 507 | if (lbRc) |
| 508 | _printf("\nSuccess (%u ms), PID=%u\n\n", nStartDuration, lpProcessInformation->dwProcessId); |
| 509 | else |
| 510 | _printf("\nFailed (%u ms), Error code=%u(x%04X)\n", nStartDuration, dwErr, dwErr); |
| 511 | } |
| 512 | #endif |
| 513 | |
| 514 | #ifdef _DEBUG |
| 515 | OnProcessCreatedDbg(lbRc, dwErr, lpProcessInformation, nullptr); |
| 516 | #endif |
| 517 | |
| 518 | if (!abSkipWowChange) |
| 519 | { |
| 520 | wow.Restore(); |
| 521 | } |
| 522 |
no test coverage detected