From b42eb08ec6bcee9e1a98d3ff159f1de6a9003c52 Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Thu, 1 Jul 2021 12:26:58 +0300 Subject: [PATCH] Start PowerToys Run through the ActionRunner (#12043) --- src/common/utils/elevation.h | 12 ++---------- src/modules/launcher/Microsoft.Launcher/dllmain.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/common/utils/elevation.h b/src/common/utils/elevation.h index 93e450675d..0910a69328 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 6f7777d4cd..2b795a35f4 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"); + } } } }