From 6869decf4bfabde36dfdef840afd9e7d27bfd257 Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Sun, 26 Oct 2025 15:48:44 +0100 Subject: [PATCH 1/5] Feature: RDP Admin session --- .../Resources/Strings.Designer.cs | 10 ++ .../Resources/Strings.resx | 3 + .../RemoteDesktop/RemoteDesktop.cs | 16 +-- .../RemoteDesktop/RemoteDesktopSessionInfo.cs | 1 + .../Controls/RemoteDesktopControl.xaml.cs | 7 +- .../RemoteDesktopConnectViewModel.cs | 129 +++++++++++------- .../ViewModels/RemoteDesktopHostViewModel.cs | 19 ++- .../Views/RemoteDesktopConnectDialog.xaml | 20 ++- 8 files changed, 137 insertions(+), 68 deletions(-) diff --git a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs index 7474254302..9cfdb253aa 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs +++ b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -644,6 +645,15 @@ public static string AdjustScreenAutomatically { } } + /// + /// Looks up a localized string similar to Admin (console) session. + /// + public static string AdminConsoleSession { + get { + return ResourceManager.GetString("AdminConsoleSession", resourceCulture); + } + } + /// /// Looks up a localized string similar to Administrator. /// diff --git a/Source/NETworkManager.Localization/Resources/Strings.resx b/Source/NETworkManager.Localization/Resources/Strings.resx index 56be8078c4..ec8798c515 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.resx @@ -3996,4 +3996,7 @@ Right-click for more options. Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + + Admin (console) session + \ No newline at end of file diff --git a/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktop.cs b/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktop.cs index b95f980f0d..f6a756cb8d 100644 --- a/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktop.cs +++ b/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktop.cs @@ -4,8 +4,8 @@ namespace NETworkManager.Models.RemoteDesktop; public static class RemoteDesktop { - public static List ScreenResolutions => new() - { + public static List ScreenResolutions => + [ "640x480", "800x600", "1024x768", @@ -18,15 +18,15 @@ public static class RemoteDesktop "1400x1050", "1680x1050", "1920x1080" - }; + ]; - public static List ColorDepths => new() - { + public static List ColorDepths => + [ 15, 16, 24, 32 - }; + ]; public static RemoteDesktopKeystrokeInfo GetKeystroke(Keystroke keystroke) { @@ -35,8 +35,8 @@ public static RemoteDesktopKeystrokeInfo GetKeystroke(Keystroke keystroke) switch (keystroke) { case Keystroke.CtrlAltDel: - info.ArrayKeyUp = new[] { false, false, false, true, true, true }; - info.KeyData = new[] { 0x1d, 0x38, 0x53, 0x53, 0x38, 0x1d }; + info.ArrayKeyUp = [false, false, false, true, true, true]; + info.KeyData = [0x1d, 0x38, 0x53, 0x53, 0x38, 0x1d]; break; } diff --git a/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktopSessionInfo.cs b/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktopSessionInfo.cs index 1e50f1ff59..106a19b7be 100644 --- a/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktopSessionInfo.cs +++ b/Source/NETworkManager.Models/RemoteDesktop/RemoteDesktopSessionInfo.cs @@ -9,6 +9,7 @@ public class RemoteDesktopSessionInfo public string Username { get; set; } public string Domain { get; set; } public SecureString Password { get; set; } + public bool AdminSession { get; set; } public int Port { get; set; } public bool AdjustScreenAutomatically { get; set; } public bool UseCurrentViewSize { get; set; } diff --git a/Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs b/Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs index 3ad004fdac..fde9e58ca5 100644 --- a/Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs +++ b/Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs @@ -212,6 +212,9 @@ private void Connect() RdpClient.AdvancedSettings9.ClearTextPassword = SecureStringHelper.ConvertToString(_sessionInfo.Password); } + // Admin (console) session + RdpClient.AdvancedSettings9.ConnectToAdministerServer = _sessionInfo.AdminSession; + // Network RdpClient.AdvancedSettings9.RDPPort = _sessionInfo.Port; @@ -716,8 +719,4 @@ private void WindowsFormsHost_DpiChanged(object sender, DpiChangedEventArgs e) AdjustScreen(force: true); } #endregion - - - - } diff --git a/Source/NETworkManager/ViewModels/RemoteDesktopConnectViewModel.cs b/Source/NETworkManager/ViewModels/RemoteDesktopConnectViewModel.cs index b5da531b84..fc445710e0 100644 --- a/Source/NETworkManager/ViewModels/RemoteDesktopConnectViewModel.cs +++ b/Source/NETworkManager/ViewModels/RemoteDesktopConnectViewModel.cs @@ -1,56 +1,18 @@ -using System; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using System; using System.ComponentModel; using System.Security; using System.Windows.Data; using System.Windows.Input; -using NETworkManager.Settings; -using NETworkManager.Utilities; namespace NETworkManager.ViewModels; public class RemoteDesktopConnectViewModel : ViewModelBase { + #region Variables private bool _connectAs; - private string _domain; - - private string _host; - - private bool _isPasswordEmpty = true; - - private string _name; - - private SecureString _password = new(); - - private bool _useCredentials; - - private string _username; - - public RemoteDesktopConnectViewModel(Action connectCommand, - Action cancelHandler, (string Name, string Host)? connectAsOptions = null) - { - ConnectCommand = new RelayCommand(_ => connectCommand(this)); - CancelCommand = new RelayCommand(_ => cancelHandler(this)); - - if (connectAsOptions == null) - { - HostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.RemoteDesktop_HostHistory); - } - else - { - ConnectAs = true; - - UseCredentials = true; - - Name = connectAsOptions.Value.Name; - Host = connectAsOptions.Value.Host; - } - } - - public ICommand ConnectCommand { get; } - - public ICommand CancelCommand { get; } - public bool ConnectAs { get => _connectAs; @@ -64,6 +26,8 @@ public bool ConnectAs } } + private string _name; + public string Name { get => _name; @@ -77,6 +41,8 @@ public string Name } } + private string _host; + public string Host { get => _host; @@ -92,6 +58,8 @@ public string Host public ICollectionView HostHistoryView { get; } + private bool _useCredentials; + public bool UseCredentials { get => _useCredentials; @@ -105,6 +73,23 @@ public bool UseCredentials } } + private string _domain; + + public string Domain + { + get => _domain; + set + { + if (value == _domain) + return; + + _domain = value; + OnPropertyChanged(); + } + } + + private string _username; + public string Username { get => _username; @@ -118,19 +103,23 @@ public string Username } } - public string Domain + private bool _isPasswordEmpty = true; + + public bool IsPasswordEmpty { - get => _domain; + get => _isPasswordEmpty; set { - if (value == _domain) + if (value == _isPasswordEmpty) return; - _domain = value; + _isPasswordEmpty = value; OnPropertyChanged(); } } + private SecureString _password = new(); + public SecureString Password { get => _password; @@ -147,18 +136,57 @@ public SecureString Password } } - public bool IsPasswordEmpty + private bool _adminSession; + + public bool AdminSession { - get => _isPasswordEmpty; + get => _adminSession; set { - if (value == _isPasswordEmpty) + if (value == _adminSession) return; - _isPasswordEmpty = value; + _adminSession = value; OnPropertyChanged(); } } + #endregion + + #region Constructor + + public RemoteDesktopConnectViewModel(Action connectCommand, + Action cancelHandler, (string Name, string Host, bool AdminSession)? connectAsOptions = null) + { + ConnectCommand = new RelayCommand(_ => connectCommand(this)); + CancelCommand = new RelayCommand(_ => cancelHandler(this)); + + if (connectAsOptions == null) + { + HostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.RemoteDesktop_HostHistory); + } + else + { + ConnectAs = true; + + UseCredentials = true; + + Name = connectAsOptions.Value.Name; + Host = connectAsOptions.Value.Host; + + AdminSession = connectAsOptions.Value.AdminSession; + } + } + + #endregion + + #region Commands + + public ICommand ConnectCommand { get; } + + public ICommand CancelCommand { get; } + #endregion + + #region Methods /// /// Check if the passwords are valid. @@ -167,4 +195,5 @@ private void ValidatePassword() { IsPasswordEmpty = Password == null || Password.Length == 0; } + #endregion } \ No newline at end of file diff --git a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs index 66da810e9c..5573aa979b 100644 --- a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs @@ -205,7 +205,7 @@ public bool IsProfileFilterSet private readonly GroupExpanderStateStore _groupExpanderStateStore = new(); public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore; - + private bool _canProfileWidthChange = true; private double _tempProfileWidth; @@ -481,7 +481,7 @@ private void ClearProfileFilterAction() _searchDisabled = true; Search = string.Empty; _searchDisabled = false; - + foreach (var tag in ProfileFilterTags) tag.IsSelected = false; @@ -504,7 +504,7 @@ private void CollapseAllProfileGroupsAction() { SetIsExpandedForAllProfileGroups(false); } - + public ItemActionCallback CloseItemCommand => CloseItemAction; private static void CloseItemAction(ItemActionCallbackArgs args) @@ -552,6 +552,8 @@ private async Task Connect(string host = null) sessionInfo.Password = instance.Password; } + sessionInfo.AdminSession = instance.AdminSession; + // Add to history // Note: The history can only be updated after the values have been read. // Otherwise, in some cases, incorrect values are taken over. @@ -612,12 +614,19 @@ private async Task ConnectProfileAs() sessionInfo.Password = instance.Password; } + sessionInfo.AdminSession = instance.AdminSession; + Connect(sessionInfo, instance.Name); }, async _ => { await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); ConfigurationManager.OnDialogClose(); - }, (profileInfo.Name, profileInfo.RemoteDesktop_Host)); + }, + ( + profileInfo.Name, + profileInfo.RemoteDesktop_Host, + true + )); customDialog.Content = new RemoteDesktopConnectDialog { @@ -659,7 +668,7 @@ private void SetIsExpandedForAllProfileGroups(bool isExpanded) foreach (var group in Profiles.Groups.Cast()) GroupExpanderStateStore[group.Name.ToString()] = isExpanded; } - + private void ResizeProfile(bool dueToChangedSize) { _canProfileWidthChange = false; diff --git a/Source/NETworkManager/Views/RemoteDesktopConnectDialog.xaml b/Source/NETworkManager/Views/RemoteDesktopConnectDialog.xaml index 18bdb0454a..252b13bd9c 100644 --- a/Source/NETworkManager/Views/RemoteDesktopConnectDialog.xaml +++ b/Source/NETworkManager/Views/RemoteDesktopConnectDialog.xaml @@ -22,6 +22,8 @@ + + @@ -126,7 +128,23 @@ - + + + + diff --git a/Source/NETworkManager/Resources/Styles/ToolTipStyles.xaml b/Source/NETworkManager/Resources/Styles/ToolTipStyles.xaml index e0e0fc6915..fc25c1508f 100644 --- a/Source/NETworkManager/Resources/Styles/ToolTipStyles.xaml +++ b/Source/NETworkManager/Resources/Styles/ToolTipStyles.xaml @@ -8,7 +8,7 @@ - - - @@ -1061,11 +1058,11 @@ - - - - @@ -1159,10 +1156,10 @@ - - - - @@ -2395,11 +2393,11 @@ - - - - @@ -2493,10 +2491,10 @@ - -