Start PowerToys Run through the ActionRunner (#12043)

This commit is contained in:
Mykhailo Pylyp 2021-07-01 12:26:58 +03:00 committed by jaimecbernardo
parent 58e2a30837
commit 831bf999bc
2 changed files with 14 additions and 11 deletions

View file

@ -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;

View file

@ -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");
}
}
}
}