diff --git a/PowerToys.slnx b/PowerToys.slnx index 568d2e4e47..d7dea8fef9 100644 --- a/PowerToys.slnx +++ b/PowerToys.slnx @@ -350,7 +350,6 @@ - diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc deleted file mode 100644 index 5fa3c8b90d..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include "resource.h" -#include "../../../common/version/version.h" - -#define APSTUDIO_READONLY_SYMBOLS -#include "winres.h" -#undef APSTUDIO_READONLY_SYMBOLS - -1 VERSIONINFO -FILEVERSION FILE_VERSION -PRODUCTVERSION PRODUCT_VERSION -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG -FILEFLAGS VS_FF_DEBUG -#else -FILEFLAGS 0x0L -#endif -FILEOS VOS_NT_WINDOWS32 -FILETYPE VFT_DLL -FILESUBTYPE VFT2_UNKNOWN -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" // US English (0x0409), Unicode (0x04B0) charset - BEGIN - VALUE "CompanyName", COMPANY_NAME - VALUE "FileDescription", FILE_DESCRIPTION - VALUE "FileVersion", FILE_VERSION_STRING - VALUE "InternalName", INTERNAL_NAME - VALUE "LegalCopyright", COPYRIGHT_NOTE - VALUE "OriginalFilename", ORIGINAL_FILENAME - VALUE "ProductName", PRODUCT_NAME - VALUE "ProductVersion", PRODUCT_VERSION_STRING - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 // US English (0x0409), Unicode (1200) charset - END -END diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj deleted file mode 100644 index 068a0ad590..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - 17.0 - Win32Proj - {b9420661-b0e4-4241-abd4-4a27a1f64250} - EnvironmentVariablesModuleInterface - EnvironmentVariablesModuleInterface - - - - DynamicLibrary - true - v143 - Unicode - - - DynamicLibrary - false - v143 - true - Unicode - - - - - - - - - - - - ..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\ - PowerToys.EnvironmentVariablesModuleInterface - - - - Level3 - true - WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - false - - - - - Level3 - true - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - false - - - - - $(SolutionDir)src;$(SolutionDir)src\modules;$(SolutionDir)src\common\Telemetry;%(AdditionalIncludeDirectories) - - - - - - - - - - - - - Create - - - - - - - - - - - - {d9b8fc84-322a-4f9f-bbb9-20915c47ddfd} - - - {6955446d-23f7-4023-9bb3-8657f904af99} - - - {cc6e41ac-8174-4e8a-8d22-85dd7f4851df} - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters deleted file mode 100644 index 8ecdef4543..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters +++ /dev/null @@ -1,53 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Resource Files - - - Resource Files - - - - - - Resource Files - - - \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx deleted file mode 100644 index d9331c4ad0..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Environment Variables - - \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp deleted file mode 100644 index a4158d1c66..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp +++ /dev/null @@ -1,280 +0,0 @@ -// dllmain.cpp : Defines the entry point for the DLL application. -#include "pch.h" - -#include "Generated Files/resource.h" -#include "trace.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -extern "C" IMAGE_DOS_HEADER __ImageBase; - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - Trace::RegisterProvider(); - break; - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - Trace::UnregisterProvider(); - break; - } - return TRUE; -} - -namespace -{ - // Name of the powertoy module. - inline const std::wstring ModuleKey = L"EnvironmentVariables"; -} - -class EnvironmentVariablesModuleInterface : public PowertoyModuleIface -{ -private: - bool m_enabled = false; - - std::wstring app_name; - - //contains the non localized key of the powertoy - std::wstring app_key; - - HANDLE m_hProcess = nullptr; - - HANDLE m_hShowEvent; - - EventWaiter m_showEventWaiter; - - HANDLE m_hShowAdminEvent; - - EventWaiter m_showAdminEventWaiter; - - bool is_process_running() - { - return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT; - } - - void bring_process_to_front() - { - auto enum_windows = [](HWND hwnd, LPARAM param) -> BOOL { - HANDLE process_handle = reinterpret_cast(param); - DWORD window_process_id = 0; - - GetWindowThreadProcessId(hwnd, &window_process_id); - if (GetProcessId(process_handle) == window_process_id) - { - SetForegroundWindow(hwnd); - return FALSE; - } - return TRUE; - }; - - EnumWindows(enum_windows, (LPARAM)m_hProcess); - } - - void launch_process(bool runas) - { - Logger::trace("EnvironmentVariablesModuleInterface::launch_process()"); - unsigned long powertoys_pid = GetCurrentProcessId(); - - std::wstring executable_args = L""; - executable_args.append(std::to_wstring(powertoys_pid)); - - SHELLEXECUTEINFOW sei{ sizeof(sei) }; - sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI }; - sei.lpFile = L"WinUI3Apps\\PowerToys.EnvironmentVariables.exe"; - sei.nShow = SW_SHOWNORMAL; - sei.lpParameters = executable_args.data(); - - if (runas) - { - sei.lpVerb = L"runas"; - } - - if (ShellExecuteExW(&sei)) - { - Logger::trace("Successfully started the Environment Variables process"); - } - else - { - Logger::error(L"Environment Variables failed to start. {}", get_last_error_or_default(GetLastError())); - } - - m_hProcess = sei.hProcess; - } - -public: - EnvironmentVariablesModuleInterface() - { - app_name = GET_RESOURCE_STRING(IDS_ENVIRONMENT_VARIABLES_NAME); - app_key = ModuleKey; - LoggerHelpers::init_logger(app_key, L"ModuleInterface", LogSettings::environmentVariablesLoggerName); - - m_hShowEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT); - if (!m_hShowEvent) - { - Logger::error(L"Failed to create show Environment Variables event"); - auto message = get_last_error_message(GetLastError()); - if (message.has_value()) - { - Logger::error(message.value()); - } - } - - m_hShowAdminEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT); - if (!m_hShowAdminEvent) - { - Logger::error(L"Failed to create show Environment Variables admin event"); - auto message = get_last_error_message(GetLastError()); - if (message.has_value()) - { - Logger::error(message.value()); - } - } - - m_showEventWaiter = EventWaiter(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT, [&](int err) { - if (m_enabled && err == ERROR_SUCCESS) - { - Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT); - - if (is_process_running()) - { - bring_process_to_front(); - } - else - { - launch_process(false); - } - - Trace::ActivateEnvironmentVariables(); - } - }); - - m_showAdminEventWaiter = EventWaiter(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT, [&](int err) { - if (m_enabled && err == ERROR_SUCCESS) - { - Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT); - - if (is_process_running()) - { - bring_process_to_front(); - } - else - { - launch_process(true); - } - - Trace::ActivateEnvironmentVariables(); - } - }); - } - - ~EnvironmentVariablesModuleInterface() - { - m_enabled = false; - } - - // Destroy the powertoy and free memory - virtual void destroy() override - { - Logger::trace("EnvironmentVariablesModuleInterface::destroy()"); - - if (m_hShowEvent) - { - CloseHandle(m_hShowEvent); - m_hShowEvent = nullptr; - } - - if (m_hShowAdminEvent) - { - CloseHandle(m_hShowAdminEvent); - m_hShowAdminEvent = nullptr; - } - - delete this; - } - - // Return the localized display name of the powertoy - virtual const wchar_t* get_name() override - { - return app_name.c_str(); - } - - // Return the non localized key of the powertoy, this will be cached by the runner - virtual const wchar_t* get_key() override - { - return app_key.c_str(); - } - - // Return the configured status for the gpo policy for the module - virtual powertoys_gpo::gpo_rule_configured_t gpo_policy_enabled_configuration() override - { - return powertoys_gpo::getConfiguredEnvironmentVariablesEnabledValue(); - } - - virtual bool get_config(wchar_t* /*buffer*/, int* /*buffer_size*/) override - { - return false; - } - - virtual void call_custom_action(const wchar_t* /*action*/) override - { - } - - virtual void set_config(const wchar_t* /*config*/) override - { - } - - virtual bool is_enabled() override - { - return m_enabled; - } - - virtual void enable() - { - Logger::trace("EnvironmentVariablesModuleInterface::enable()"); - m_enabled = true; - Trace::EnableEnvironmentVariables(true); - } - - virtual void disable() - { - Logger::trace("EnvironmentVariablesModuleInterface::disable()"); - if (m_enabled) - { - if (m_hShowEvent) - { - ResetEvent(m_hShowEvent); - } - - if (m_hShowAdminEvent) - { - ResetEvent(m_hShowAdminEvent); - } - - TerminateProcess(m_hProcess, 1); - } - - m_enabled = false; - Trace::EnableEnvironmentVariables(false); - } -}; - -extern "C" __declspec(dllexport) PowertoyModuleIface * __cdecl powertoy_create() -{ - return new EnvironmentVariablesModuleInterface(); -} \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/packages.config b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/packages.config deleted file mode 100644 index 09bfc449e2..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp deleted file mode 100644 index 64b7eef6d6..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// pch.cpp: source file corresponding to the pre-compiled header - -#include "pch.h" - -// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h deleted file mode 100644 index 308dff2b3a..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h +++ /dev/null @@ -1,17 +0,0 @@ -// pch.h: This is a precompiled header file. -// Files listed below are compiled only once, improving build performance for future builds. -// This also affects IntelliSense performance, including code completion and many code browsing features. -// However, files listed here are ALL re-compiled if any one of them is updated between builds. -// Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files -#include - -#include -#include - -#endif //PCH_H diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h deleted file mode 100644 index da4dc076a8..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h +++ /dev/null @@ -1,13 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by AlwaysOnTopModuleInterface.rc - -////////////////////////////// -// Non-localizable - -#define FILE_DESCRIPTION "PowerToys Environment Variables Module" -#define INTERNAL_NAME "PowerToys.EnvironmentVariablesModuleInterface" -#define ORIGINAL_FILENAME "PowerToys.EnvironmentVariablesModuleInterface.dll" - -// Non-localizable -////////////////////////////// diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp deleted file mode 100644 index 6cb84aed08..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "pch.h" -#include "trace.h" - -#include - -TRACELOGGING_DEFINE_PROVIDER( - g_hProvider, - "Microsoft.PowerToys", - // {38e8889b-9731-53f5-e901-e8a7c1753074} - (0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74), - TraceLoggingOptionProjectTelemetry()); - -// Log if the user has Environment Variables enabled or disabled -void Trace::EnableEnvironmentVariables(const bool enabled) noexcept -{ - TraceLoggingWriteWrapper( - g_hProvider, - "EnvironmentVariables_EnableEnvironmentVariables", - ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), - TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), - TraceLoggingBoolean(enabled, "Enabled")); -} - -// Log that the user tried to activate the editor -void Trace::ActivateEnvironmentVariables() noexcept -{ - TraceLoggingWriteWrapper( - g_hProvider, - "EnvironmentVariables_Activate", - ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), - TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); -} diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h deleted file mode 100644 index fa37b043b5..0000000000 --- a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -class Trace : public telemetry::TraceBase -{ -public: - // Log if the user has EnvironmentVariables enabled or disabled - static void EnableEnvironmentVariables(const bool enabled) noexcept; - - // Log that the user tried to activate the editor - static void ActivateEnvironmentVariables() noexcept; -}; diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs index f82da1466c..ca3e74017d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs @@ -2,6 +2,8 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; +using System.IO; using System.Threading; using global::Windows.System; @@ -52,13 +54,24 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout case ModuleType.EnvironmentVariables: // Launch Environment Variables { bool launchAdmin = SettingsRepository.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator; - string eventName = !App.IsElevated && launchAdmin - ? Constants.ShowEnvironmentVariablesAdminSharedEvent() - : Constants.ShowEnvironmentVariablesSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!App.IsElevated && launchAdmin) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"); + } + catch (Exception ex) + { + Logger.LogError($"[Flyout->LaunchPage] Launch of Environment Variables failed", ex); } } @@ -75,13 +88,24 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout case ModuleType.Hosts: // Launch Hosts { bool launchAdmin = SettingsRepository.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator; - string eventName = !App.IsElevated && launchAdmin - ? Constants.ShowHostsAdminSharedEvent() - : Constants.ShowHostsSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!App.IsElevated && launchAdmin) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.Hosts.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.Hosts.exe"); + } + catch (Exception ex) + { + Logger.LogError($"[Flyout->LaunchPage] Launch of Hosts failed", ex); } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs index 3e2b66b9d6..4dfadfb283 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Diagnostics; +using System.IO; using System.Threading; - +using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel; @@ -38,13 +41,24 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views private void Launch_EnvironmentVariables_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { bool launchAdmin = SettingsRepository.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator; - string eventName = !App.IsElevated && launchAdmin - ? Constants.ShowEnvironmentVariablesAdminSharedEvent() - : Constants.ShowEnvironmentVariablesSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!App.IsElevated && launchAdmin) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"); + } + catch (Exception ex) + { + Logger.LogError($"[EnvironmentVariablesViewModel] Launch failed", ex); } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs index 0a98df472e..5d5839f4b7 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Diagnostics; +using System.IO; using System.Threading; - +using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel; @@ -38,13 +41,24 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views private void Launch_Hosts_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { bool launchAdmin = SettingsRepository.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator; - string eventName = !App.IsElevated && launchAdmin - ? Constants.ShowHostsAdminSharedEvent() - : Constants.ShowHostsSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!App.IsElevated && launchAdmin) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.Hosts.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.Hosts.exe"); + } + catch (Exception ex) + { + Logger.LogError($"[OobeHosts] Launch failed", ex); } } diff --git a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs index e256278d00..e4ba08cbc1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs @@ -3,10 +3,13 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; +using System.IO; using System.Runtime.CompilerServices; using System.Threading; using global::PowerToys.GPOWrapper; +using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; @@ -106,13 +109,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels public void Launch() { - string eventName = !_isElevated && LaunchAdministrator - ? Constants.ShowEnvironmentVariablesAdminSharedEvent() - : Constants.ShowEnvironmentVariablesSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!_isElevated && LaunchAdministrator) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.EnvironmentVariables.exe"); + } + catch (Exception e) + { + Logger.LogError($"[EnvironmentVariablesViewModel] Launch failed", e); } } diff --git a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs index 04eea7c1e4..8c6e02fc31 100644 --- a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs @@ -3,9 +3,12 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; +using System.IO; using System.Runtime.CompilerServices; using System.Threading; using global::PowerToys.GPOWrapper; +using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; @@ -241,13 +244,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels public void Launch() { - string eventName = !_isElevated && LaunchAdministrator - ? Constants.ShowHostsAdminSharedEvent() - : Constants.ShowHostsSharedEvent(); - - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName)) + try { - eventHandle.Set(); + if (!_isElevated && LaunchAdministrator) + { + Process.Start(new ProcessStartInfo() + { + FileName = Path.GetFullPath("WinUI3Apps\\PowerToys.Hosts.exe"), + Verb = "runas", + UseShellExecute = true, + }); + return; + } + + Process.Start("WinUI3Apps\\PowerToys.Hosts.exe"); + } + catch (Exception e) + { + Logger.LogError($"[HostsViewModel] Launch failed", e); } }