[runner]Fix non-elevated restart loop (#17853)

This commit is contained in:
Jaime Bernardo
2022-04-21 14:59:29 +01:00
committed by GitHub
parent b463cb11aa
commit d683ab0afd
2 changed files with 4 additions and 5 deletions

View File

@@ -443,10 +443,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
if (is_restart_scheduled()) if (is_restart_scheduled())
{ {
if (!restart_if_scheduled()) if (!restart_if_scheduled())
{ {
Logger::warn("Scheduled restart failed. Trying restart as admin as fallback..."); // If it's not possible to restart non-elevated due to some condition in the user's configuration, user should start PowerToys manually.
restart_same_elevation(); Logger::warn("Scheduled restart failed. Couldn't restart non-elevated. PowerToys exits here because retrying it would just mean failing in a loop.");
} }
} }
stop_tray_icon(); stop_tray_icon();

View File

@@ -41,7 +41,7 @@ bool restart_if_scheduled()
case RestartAsElevatedOpenSettings: case RestartAsElevatedOpenSettings:
return run_elevated(exe_path.get(), L"--open-settings"); return run_elevated(exe_path.get(), L"--open-settings");
case RestartAsNonElevated: case RestartAsNonElevated:
return run_non_elevated(exe_path.get(), L"--dont-elevate", NULL); return run_non_elevated(exe_path.get(), L"", NULL);
default: default:
return false; return false;
} }
@@ -52,5 +52,5 @@ bool restart_same_elevation()
constexpr DWORD exe_path_size = 0xFFFF; constexpr DWORD exe_path_size = 0xFFFF;
auto exe_path = std::make_unique<wchar_t[]>(exe_path_size); auto exe_path = std::make_unique<wchar_t[]>(exe_path_size);
GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size); GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size);
return run_same_elevation(exe_path.get(), L"--dont-elevate", nullptr); return run_same_elevation(exe_path.get(), L"", nullptr);
} }