[runner, color picker, run] remove os dection (#10648)
This commit is contained in:
parent
97fdf10cea
commit
aa5ff65b54
|
@ -6,7 +6,6 @@
|
|||
#include "Generated Files/resource.h"
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/SettingsAPI/settings_objects.h>
|
||||
#include <common/utils/os-detect.h>
|
||||
#include <common/utils/resources.h>
|
||||
|
||||
#include <colorPicker/ColorPicker/ColorPickerConstants.h>
|
||||
|
@ -227,12 +226,8 @@ public:
|
|||
{
|
||||
ResetEvent(send_telemetry_event);
|
||||
ResetEvent(m_hInvokeEvent);
|
||||
// use only with new settings?
|
||||
if (UseNewSettings())
|
||||
{
|
||||
launch_process();
|
||||
m_enabled = true;
|
||||
}
|
||||
launch_process();
|
||||
m_enabled = true;
|
||||
};
|
||||
|
||||
virtual void disable()
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <common/utils/elevation.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/resources.h>
|
||||
#include <common/utils/os-detect.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
#include <filesystem>
|
||||
|
@ -185,89 +184,86 @@ public:
|
|||
Logger::info("Launcher is enabling");
|
||||
ResetEvent(m_hEvent);
|
||||
ResetEvent(send_telemetry_event);
|
||||
// Start PowerLauncher.exe only if the OS is 19H1 or higher
|
||||
if (UseNewSettings())
|
||||
|
||||
unsigned long powertoys_pid = GetCurrentProcessId();
|
||||
|
||||
if (!is_process_elevated(false))
|
||||
{
|
||||
unsigned long powertoys_pid = GetCurrentProcessId();
|
||||
Logger::trace("Starting PowerToys Run from not elevated process");
|
||||
std::wstring executable_args;
|
||||
executable_args += L" -powerToysPid ";
|
||||
executable_args += std::to_wstring(powertoys_pid);
|
||||
executable_args += L" --centralized-kb-hook";
|
||||
|
||||
if (!is_process_elevated(false))
|
||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
||||
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
||||
sei.lpFile = L"modules\\launcher\\PowerLauncher.exe";
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
sei.lpParameters = executable_args.data();
|
||||
|
||||
if (ShellExecuteExW(&sei))
|
||||
{
|
||||
Logger::trace("Starting PowerToys Run from not elevated process");
|
||||
std::wstring executable_args;
|
||||
executable_args += L" -powerToysPid ";
|
||||
executable_args += std::to_wstring(powertoys_pid);
|
||||
executable_args += L" --centralized-kb-hook";
|
||||
|
||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
||||
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
||||
sei.lpFile = L"modules\\launcher\\PowerLauncher.exe";
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
sei.lpParameters = executable_args.data();
|
||||
|
||||
if (ShellExecuteExW(&sei))
|
||||
{
|
||||
m_enabled = true;
|
||||
m_hProcess = sei.hProcess;
|
||||
Logger::trace("Started PowerToys Run. Handle {}", m_hProcess);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::error("Launcher failed to start");
|
||||
}
|
||||
m_enabled = true;
|
||||
m_hProcess = sei.hProcess;
|
||||
Logger::trace("Started PowerToys Run. Handle {}", m_hProcess);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::trace("Starting PowerToys Run from elevated process");
|
||||
std::wstring action_runner_path = get_module_folderpath();
|
||||
Logger::error("Launcher failed to start");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::trace("Starting PowerToys Run from elevated process");
|
||||
std::wstring action_runner_path = get_module_folderpath();
|
||||
|
||||
std::wstring params;
|
||||
params += L"-run-non-elevated ";
|
||||
params += L"-target modules\\launcher\\PowerLauncher.exe ";
|
||||
params += L"-pidFile ";
|
||||
params += POWER_LAUNCHER_PID_SHARED_FILE;
|
||||
params += L" -powerToysPid " + std::to_wstring(powertoys_pid) + L" ";
|
||||
params += L"--centralized-kb-hook ";
|
||||
std::wstring params;
|
||||
params += L"-run-non-elevated ";
|
||||
params += L"-target modules\\launcher\\PowerLauncher.exe ";
|
||||
params += L"-pidFile ";
|
||||
params += POWER_LAUNCHER_PID_SHARED_FILE;
|
||||
params += L" -powerToysPid " + std::to_wstring(powertoys_pid) + L" ";
|
||||
params += L"--centralized-kb-hook ";
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
auto err = get_last_error_message(GetLastError());
|
||||
Logger::error(L"Failed to create FileMapping {}. {}", POWER_LAUNCHER_PID_SHARED_FILE, err.has_value() ? err.value() : L"");
|
||||
return;
|
||||
}
|
||||
|
||||
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
||||
if (pidBuffer)
|
||||
{
|
||||
*pidBuffer = 0;
|
||||
m_hProcess = NULL;
|
||||
|
||||
if (run_non_elevated(action_runner_path, params, pidBuffer))
|
||||
{
|
||||
auto err = get_last_error_message(GetLastError());
|
||||
Logger::error(L"Failed to create FileMapping {}. {}", POWER_LAUNCHER_PID_SHARED_FILE, err.has_value() ? err.value() : L"");
|
||||
return;
|
||||
}
|
||||
|
||||
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
||||
if (pidBuffer)
|
||||
{
|
||||
*pidBuffer = 0;
|
||||
m_hProcess = NULL;
|
||||
|
||||
if (run_non_elevated(action_runner_path, params, pidBuffer))
|
||||
Logger::trace("Started PowerToys Run Process. PID {}", *pidBuffer);
|
||||
m_enabled = true;
|
||||
const int maxRetries = 80;
|
||||
for (int retry = 0; retry < maxRetries; ++retry)
|
||||
{
|
||||
Logger::trace("Started PowerToys Run Process. PID {}", *pidBuffer);
|
||||
m_enabled = true;
|
||||
const int maxRetries = 80;
|
||||
for (int retry = 0; retry < maxRetries; ++retry)
|
||||
Sleep(50);
|
||||
DWORD pid = *pidBuffer;
|
||||
if (pid)
|
||||
{
|
||||
Sleep(50);
|
||||
DWORD pid = *pidBuffer;
|
||||
if (pid)
|
||||
{
|
||||
m_hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
|
||||
Logger::trace("Opened PowerToys Run Process. Handle {}", m_hProcess);
|
||||
break;
|
||||
}
|
||||
m_hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
|
||||
Logger::trace("Opened PowerToys Run Process. Handle {}", m_hProcess);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::error("Failed to start PowerToys Run");
|
||||
}
|
||||
}
|
||||
CloseHandle(hMapFile);
|
||||
else
|
||||
{
|
||||
Logger::error("Failed to start PowerToys Run");
|
||||
}
|
||||
}
|
||||
CloseHandle(hMapFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <common/version/helper.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/elevation.h>
|
||||
#include <common/utils/os-detect.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/timeutil.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
@ -367,12 +366,12 @@ void run_settings_window(bool showOobeWindow)
|
|||
|
||||
BOOL process_created = false;
|
||||
|
||||
// Due to a bug in .NET, running the Settings process as non-elevated
|
||||
// from an elevated process sometimes results in a crash.
|
||||
// TODO: Revisit this after switching to .NET 5
|
||||
if (is_process_elevated() && !UseNewSettings())
|
||||
if (is_process_elevated())
|
||||
{
|
||||
process_created = run_settings_non_elevated(executable_path.c_str(), executable_args.data(), &process_info);
|
||||
// TODO: Revisit this after switching to .NET 5
|
||||
// Due to a bug in .NET, running the Settings process as non-elevated
|
||||
// from an elevated process sometimes results in a crash.
|
||||
// process_created = run_settings_non_elevated(executable_path.c_str(), executable_args.data(), &process_info);
|
||||
}
|
||||
|
||||
if (FALSE == process_created)
|
||||
|
|
Loading…
Reference in a new issue