[PowerToys Run] run non-elevated when runner is elevated (#3451)

* run Launcher non-elevated

* Implemented acquiring PID of Launcher

Co-authored-by: ivan100sic <ivan100sic@gmail.com>
This commit is contained in:
Enrico Giordani
2020-05-21 19:44:32 +02:00
committed by GitHub
parent 582d1320a3
commit a856263081
5 changed files with 75 additions and 11 deletions

View File

@@ -186,7 +186,28 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
}
std::wstring_view action{ args[1] };
if (action == L"-install_dotnet")
if (action == L"-start_PowerLauncher")
{
if (is_process_elevated(false) == true)
{
drop_elevated_privileges();
}
HANDLE hMapFile = OpenFileMappingW(FILE_MAP_WRITE, FALSE, POWER_LAUNCHER_PID_SHARED_FILE);
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
if (pidBuffer)
{
*pidBuffer = 0;
run_non_elevated(L"modules\\launcher\\PowerLauncher.exe", L"", pidBuffer);
FlushViewOfFile(pidBuffer, sizeof(DWORD));
UnmapViewOfFile(pidBuffer);
}
FlushFileBuffers(hMapFile);
CloseHandle(hMapFile);
}
else if (action == L"-install_dotnet")
{
if (dotnet_is_installed())
{