[Action runner] Support running generic targets as non-elevated (#3863)
* Initial work, not tested * Forgot the most important part * Use target argument instead of hardcoded string * Removed old way of running Launcher * Completed rebase, updated some code
This commit is contained in:
parent
21929b1db2
commit
eb4b429e19
|
@ -186,22 +186,63 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|||
}
|
||||
std::wstring_view action{ args[1] };
|
||||
|
||||
if (action == L"-start_PowerLauncher")
|
||||
if (action == L"-run-non-elevated")
|
||||
{
|
||||
HANDLE hMapFile = OpenFileMappingW(FILE_MAP_WRITE, FALSE, POWER_LAUNCHER_PID_SHARED_FILE);
|
||||
if (hMapFile)
|
||||
int nextArg = 2;
|
||||
|
||||
std::wstring_view target;
|
||||
std::wstring_view pidFile;
|
||||
|
||||
while (nextArg < nArgs)
|
||||
{
|
||||
if (std::wstring_view(args[nextArg]) == L"-target" && nextArg + 1 < nArgs)
|
||||
{
|
||||
target = args[nextArg + 1];
|
||||
nextArg += 2;
|
||||
}
|
||||
else if (std::wstring_view(args[nextArg]) == L"-pidFile" && nextArg + 1 < nArgs)
|
||||
{
|
||||
pidFile = args[nextArg + 1];
|
||||
nextArg += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextArg++;
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE hMapFile = NULL;
|
||||
PDWORD pidBuffer = NULL;
|
||||
|
||||
if (!pidFile.empty())
|
||||
{
|
||||
hMapFile = OpenFileMappingW(FILE_MAP_WRITE, FALSE, pidFile.data());
|
||||
if (hMapFile)
|
||||
{
|
||||
pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
||||
if (pidBuffer)
|
||||
{
|
||||
*pidBuffer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_same_elevation(target.data(), L"", pidBuffer);
|
||||
|
||||
// cleanup
|
||||
if (!pidFile.empty())
|
||||
{
|
||||
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
||||
if (pidBuffer)
|
||||
{
|
||||
*pidBuffer = 0;
|
||||
run_same_elevation(L"modules\\launcher\\PowerLauncher.exe", L"", pidBuffer);
|
||||
FlushViewOfFile(pidBuffer, sizeof(DWORD));
|
||||
UnmapViewOfFile(pidBuffer);
|
||||
}
|
||||
|
||||
FlushFileBuffers(hMapFile);
|
||||
CloseHandle(hMapFile);
|
||||
if (hMapFile)
|
||||
{
|
||||
FlushFileBuffers(hMapFile);
|
||||
CloseHandle(hMapFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action == L"-install_dotnet")
|
||||
|
|
|
@ -145,8 +145,14 @@ public:
|
|||
else
|
||||
{
|
||||
std::wstring action_runner_path = get_module_folderpath();
|
||||
action_runner_path += L"\\action_runner.exe";
|
||||
|
||||
std::wstring params;
|
||||
params += L"-run-non-elevated ";
|
||||
params += L"-target modules\\launcher\\PowerLauncher.exe ";
|
||||
params += L"-pidFile ";
|
||||
params += POWER_LAUNCHER_PID_SHARED_FILE;
|
||||
|
||||
action_runner_path += L"\\action_runner.exe";
|
||||
// Set up the shared file from which to retrieve the PID of PowerLauncher
|
||||
HANDLE hMapFile = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(DWORD), POWER_LAUNCHER_PID_SHARED_FILE);
|
||||
if (hMapFile)
|
||||
|
@ -157,9 +163,9 @@ public:
|
|||
*pidBuffer = 0;
|
||||
m_hProcess = NULL;
|
||||
|
||||
if (run_non_elevated(action_runner_path, L"-start_PowerLauncher", nullptr))
|
||||
if (run_non_elevated(action_runner_path, params, pidBuffer))
|
||||
{
|
||||
const int maxRetries = 20;
|
||||
const int maxRetries = 80;
|
||||
for (int retry = 0; retry < maxRetries; ++retry)
|
||||
{
|
||||
Sleep(50);
|
||||
|
|
Loading…
Reference in a new issue