mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Tweaked OS Detection project structure and added os check for PT Run (#4253)
* Tweaked OS Detection project structure and added check in Launcher * Reverted formatter change to minimize diff
This commit is contained in:
@@ -125,6 +125,7 @@
|
|||||||
<ClInclude Include="keyboard_layout.h" />
|
<ClInclude Include="keyboard_layout.h" />
|
||||||
<ClInclude Include="keyboard_layout_impl.h" />
|
<ClInclude Include="keyboard_layout_impl.h" />
|
||||||
<ClInclude Include="notifications.h" />
|
<ClInclude Include="notifications.h" />
|
||||||
|
<ClInclude Include="os-detection\os-detect.h" />
|
||||||
<ClInclude Include="RestartManagement.h" />
|
<ClInclude Include="RestartManagement.h" />
|
||||||
<ClInclude Include="shared_constants.h" />
|
<ClInclude Include="shared_constants.h" />
|
||||||
<ClInclude Include="timeutil.h" />
|
<ClInclude Include="timeutil.h" />
|
||||||
@@ -159,6 +160,7 @@
|
|||||||
<ClCompile Include="monitors.cpp" />
|
<ClCompile Include="monitors.cpp" />
|
||||||
<ClCompile Include="notifications.cpp" />
|
<ClCompile Include="notifications.cpp" />
|
||||||
<ClCompile Include="on_thread_executor.cpp" />
|
<ClCompile Include="on_thread_executor.cpp" />
|
||||||
|
<ClCompile Include="os-detection\os-detect.cpp" />
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -111,6 +111,9 @@
|
|||||||
<ClInclude Include="two_way_pipe_message_ipc.h">
|
<ClInclude Include="two_way_pipe_message_ipc.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="os-detection\os-detect.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="RestartManagement.h">
|
<ClInclude Include="RestartManagement.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -183,6 +186,9 @@
|
|||||||
<ClCompile Include="two_way_pipe_message_ipc.cpp">
|
<ClCompile Include="two_way_pipe_message_ipc.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="os-detection\os-detect.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="RestartManagement.cpp">
|
<ClCompile Include="RestartManagement.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <common/common.h>
|
#include <common/common.h>
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
#include <common/os-detection/os-detect.h>
|
||||||
|
|
||||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||||
|
|
||||||
@@ -132,60 +133,64 @@ public:
|
|||||||
// Enable the powertoy
|
// Enable the powertoy
|
||||||
virtual void enable()
|
virtual void enable()
|
||||||
{
|
{
|
||||||
unsigned long powertoys_pid = GetCurrentProcessId();
|
// Start PowerLauncher.exe only if the OS is 19H1 or higher
|
||||||
|
if (UseNewSettings())
|
||||||
if (!is_process_elevated(false))
|
|
||||||
{
|
{
|
||||||
std::wstring executable_args = L"";
|
unsigned long powertoys_pid = GetCurrentProcessId();
|
||||||
executable_args.append(std::to_wstring(powertoys_pid));
|
|
||||||
|
|
||||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
if (!is_process_elevated(false))
|
||||||
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();
|
|
||||||
ShellExecuteExW(&sei);
|
|
||||||
|
|
||||||
m_hProcess = sei.hProcess;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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" " + std::to_wstring(powertoys_pid) + L" ";
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
std::wstring executable_args = L"";
|
||||||
if (pidBuffer)
|
executable_args.append(std::to_wstring(powertoys_pid));
|
||||||
{
|
|
||||||
*pidBuffer = 0;
|
|
||||||
m_hProcess = NULL;
|
|
||||||
|
|
||||||
if (run_non_elevated(action_runner_path, params, pidBuffer))
|
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();
|
||||||
|
ShellExecuteExW(&sei);
|
||||||
|
|
||||||
|
m_hProcess = sei.hProcess;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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" " + std::to_wstring(powertoys_pid) + L" ";
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
|
||||||
|
if (pidBuffer)
|
||||||
{
|
{
|
||||||
const int maxRetries = 80;
|
*pidBuffer = 0;
|
||||||
for (int retry = 0; retry < maxRetries; ++retry)
|
m_hProcess = NULL;
|
||||||
|
|
||||||
|
if (run_non_elevated(action_runner_path, params, pidBuffer))
|
||||||
{
|
{
|
||||||
Sleep(50);
|
const int maxRetries = 80;
|
||||||
DWORD pid = *pidBuffer;
|
for (int retry = 0; retry < maxRetries; ++retry)
|
||||||
if (pid)
|
|
||||||
{
|
{
|
||||||
m_hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
Sleep(50);
|
||||||
break;
|
DWORD pid = *pidBuffer;
|
||||||
|
if (pid)
|
||||||
|
{
|
||||||
|
m_hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CloseHandle(hMapFile);
|
||||||
}
|
}
|
||||||
CloseHandle(hMapFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,9 +238,6 @@
|
|||||||
<ProjectReference Include="..\common\common.vcxproj">
|
<ProjectReference Include="..\common\common.vcxproj">
|
||||||
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
|
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\common\os-detection\os-detection.vcxproj">
|
|
||||||
<Project>{e6410bfc-b341-498c-8c67-312c20cdd8d5}</Project>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\common\updating\updating.vcxproj">
|
<ProjectReference Include="..\common\updating\updating.vcxproj">
|
||||||
<Project>{17da04df-e393-4397-9cf0-84dabe11032e}</Project>
|
<Project>{17da04df-e393-4397-9cf0-84dabe11032e}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <common/json.h>
|
#include <common/json.h>
|
||||||
#include <common\settings_helpers.cpp>
|
#include <common\settings_helpers.cpp>
|
||||||
#include <os-detect.h>
|
#include <common/os-detection/os-detect.h>
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user