Skip to content

Commit

Permalink
Start PowerToys Run through the ActionRunner (#12043)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp authored and jaimecbernardo committed Jul 1, 2021
1 parent 58e2a30 commit 831bf99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/common/utils/elevation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/modules/launcher/Microsoft.Launcher/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,18 @@ class Microsoft_Launcher : public PowertoyModuleIface
}
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");
}
}
}
}
Expand Down

0 comments on commit 831bf99

Please sign in to comment.