[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

@@ -461,7 +461,7 @@ bool run_elevated(const std::wstring& file, const std::wstring& params)
}
}
bool run_non_elevated(const std::wstring& file, const std::wstring& params)
bool run_non_elevated(const std::wstring& file, const std::wstring& params, DWORD* returnPid)
{
auto executable_args = L"\"" + file + L"\"";
if (!params.empty())
@@ -521,8 +521,14 @@ bool run_non_elevated(const std::wstring& file, const std::wstring& params)
nullptr,
&siex.StartupInfo,
&process_info);
if (process_info.hProcess)
{
if (returnPid)
{
*returnPid = GetProcessId(process_info.hProcess);
}
CloseHandle(process_info.hProcess);
}
if (process_info.hThread)

View File

@@ -69,8 +69,8 @@ bool drop_elevated_privileges();
// Run command as elevated user, returns true if succeeded
bool run_elevated(const std::wstring& file, const std::wstring& params);
// Run command as non-elevated user, returns true if succeeded
bool run_non_elevated(const std::wstring& file, const std::wstring& params);
// Run command as non-elevated user, returns true if succeeded, puts the process id into returnPid if returnPid != NULL
bool run_non_elevated(const std::wstring& file, const std::wstring& params, DWORD* returnPid);
// Run command with the same elevation, returns true if succedded
bool run_same_elevation(const std::wstring& file, const std::wstring& params);
@@ -136,3 +136,5 @@ struct overloaded : Ts...
};
template<class... Ts>
overloaded(Ts...)->overloaded<Ts...>;
#define POWER_LAUNCHER_PID_SHARED_FILE L"Global\\3cbfbad4-199b-4e2c-9825-942d5d3d3c74"