diff --git a/src/common/utils/elevation.h b/src/common/utils/elevation.h index 93e450675..0910a6932 100644 --- a/src/common/utils/elevation.h +++ b/src/common/utils/elevation.h @@ -307,25 +307,17 @@ inline bool run_non_elevated(const std::wstring& file, const std::wstring& param inline bool RunNonElevatedEx(const std::wstring& file, const std::wstring& params) { - bool failedToStart = false; try { CoInitialize(nullptr); if (!ShellExecuteFromExplorer(file.c_str(), params.c_str())) { - failedToStart = true; + return false; } } catch(...) { - failedToStart = true; - } - - if (failedToStart) - { - Logger::warn(L"Failed to delegate process creation. Try a fallback"); - DWORD returnPid; - return run_non_elevated(file, params, &returnPid); + return false; } return true; diff --git a/src/modules/launcher/Microsoft.Launcher/dllmain.cpp b/src/modules/launcher/Microsoft.Launcher/dllmain.cpp index 6f7777d4c..2b795a35f 100644 --- a/src/modules/launcher/Microsoft.Launcher/dllmain.cpp +++ b/src/modules/launcher/Microsoft.Launcher/dllmain.cpp @@ -243,7 +243,18 @@ public: } else { - Logger::error(L"Failed to start the process"); + Logger::warn(L"RunNonElevatedEx() failed. Trying fallback"); + std::wstring action_runner_path = get_module_folderpath() + L"\\PowerToys.ActionRunner.exe"; + std::wstring newParams = L"-run-non-elevated -target modules\\launcher\\PowerLauncher.exe " + params; + if (run_non_elevated(action_runner_path, newParams, nullptr)) + { + processStarted = true; + Logger::trace("Started PowerToys Run Process"); + } + else + { + Logger::warn("Failed to start PowerToys Run"); + } } } }