Skip to content

Commit 6869dec

Browse files
committed
Feature: RDP Admin session
1 parent 0d335b2 commit 6869dec

File tree

8 files changed

+137
-68
lines changed

8 files changed

+137
-68
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,4 +3996,7 @@ Right-click for more options.</value>
39963996
<data name="HelpMessage_UseCustomThemes" xml:space="preserve">
39973997
<value>Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder &gt; Themes" directory. For more details, refer to the documentation.</value>
39983998
</data>
3999+
<data name="AdminConsoleSession" xml:space="preserve">
4000+
<value>Admin (console) session</value>
4001+
</data>
39994002
</root>

Source/NETworkManager.Models/RemoteDesktop/RemoteDesktop.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace NETworkManager.Models.RemoteDesktop;
44

55
public static class RemoteDesktop
66
{
7-
public static List<string> ScreenResolutions => new()
8-
{
7+
public static List<string> ScreenResolutions =>
8+
[
99
"640x480",
1010
"800x600",
1111
"1024x768",
@@ -18,15 +18,15 @@ public static class RemoteDesktop
1818
"1400x1050",
1919
"1680x1050",
2020
"1920x1080"
21-
};
21+
];
2222

23-
public static List<int> ColorDepths => new()
24-
{
23+
public static List<int> ColorDepths =>
24+
[
2525
15,
2626
16,
2727
24,
2828
32
29-
};
29+
];
3030

3131
public static RemoteDesktopKeystrokeInfo GetKeystroke(Keystroke keystroke)
3232
{
@@ -35,8 +35,8 @@ public static RemoteDesktopKeystrokeInfo GetKeystroke(Keystroke keystroke)
3535
switch (keystroke)
3636
{
3737
case Keystroke.CtrlAltDel:
38-
info.ArrayKeyUp = new[] { false, false, false, true, true, true };
39-
info.KeyData = new[] { 0x1d, 0x38, 0x53, 0x53, 0x38, 0x1d };
38+
info.ArrayKeyUp = [false, false, false, true, true, true];
39+
info.KeyData = [0x1d, 0x38, 0x53, 0x53, 0x38, 0x1d];
4040
break;
4141
}
4242

Source/NETworkManager.Models/RemoteDesktop/RemoteDesktopSessionInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class RemoteDesktopSessionInfo
99
public string Username { get; set; }
1010
public string Domain { get; set; }
1111
public SecureString Password { get; set; }
12+
public bool AdminSession { get; set; }
1213
public int Port { get; set; }
1314
public bool AdjustScreenAutomatically { get; set; }
1415
public bool UseCurrentViewSize { get; set; }

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ private void Connect()
212212
RdpClient.AdvancedSettings9.ClearTextPassword = SecureStringHelper.ConvertToString(_sessionInfo.Password);
213213
}
214214

215+
// Admin (console) session
216+
RdpClient.AdvancedSettings9.ConnectToAdministerServer = _sessionInfo.AdminSession;
217+
215218
// Network
216219
RdpClient.AdvancedSettings9.RDPPort = _sessionInfo.Port;
217220

@@ -716,8 +719,4 @@ private void WindowsFormsHost_DpiChanged(object sender, DpiChangedEventArgs e)
716719
AdjustScreen(force: true);
717720
}
718721
#endregion
719-
720-
721-
722-
723722
}
Lines changed: 79 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,18 @@
1-
using System;
1+
using NETworkManager.Settings;
2+
using NETworkManager.Utilities;
3+
using System;
24
using System.ComponentModel;
35
using System.Security;
46
using System.Windows.Data;
57
using System.Windows.Input;
6-
using NETworkManager.Settings;
7-
using NETworkManager.Utilities;
88

99
namespace NETworkManager.ViewModels;
1010

1111
public class RemoteDesktopConnectViewModel : ViewModelBase
1212
{
13+
#region Variables
1314
private bool _connectAs;
1415

15-
private string _domain;
16-
17-
private string _host;
18-
19-
private bool _isPasswordEmpty = true;
20-
21-
private string _name;
22-
23-
private SecureString _password = new();
24-
25-
private bool _useCredentials;
26-
27-
private string _username;
28-
29-
public RemoteDesktopConnectViewModel(Action<RemoteDesktopConnectViewModel> connectCommand,
30-
Action<RemoteDesktopConnectViewModel> cancelHandler, (string Name, string Host)? connectAsOptions = null)
31-
{
32-
ConnectCommand = new RelayCommand(_ => connectCommand(this));
33-
CancelCommand = new RelayCommand(_ => cancelHandler(this));
34-
35-
if (connectAsOptions == null)
36-
{
37-
HostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.RemoteDesktop_HostHistory);
38-
}
39-
else
40-
{
41-
ConnectAs = true;
42-
43-
UseCredentials = true;
44-
45-
Name = connectAsOptions.Value.Name;
46-
Host = connectAsOptions.Value.Host;
47-
}
48-
}
49-
50-
public ICommand ConnectCommand { get; }
51-
52-
public ICommand CancelCommand { get; }
53-
5416
public bool ConnectAs
5517
{
5618
get => _connectAs;
@@ -64,6 +26,8 @@ public bool ConnectAs
6426
}
6527
}
6628

29+
private string _name;
30+
6731
public string Name
6832
{
6933
get => _name;
@@ -77,6 +41,8 @@ public string Name
7741
}
7842
}
7943

44+
private string _host;
45+
8046
public string Host
8147
{
8248
get => _host;
@@ -92,6 +58,8 @@ public string Host
9258

9359
public ICollectionView HostHistoryView { get; }
9460

61+
private bool _useCredentials;
62+
9563
public bool UseCredentials
9664
{
9765
get => _useCredentials;
@@ -105,6 +73,23 @@ public bool UseCredentials
10573
}
10674
}
10775

76+
private string _domain;
77+
78+
public string Domain
79+
{
80+
get => _domain;
81+
set
82+
{
83+
if (value == _domain)
84+
return;
85+
86+
_domain = value;
87+
OnPropertyChanged();
88+
}
89+
}
90+
91+
private string _username;
92+
10893
public string Username
10994
{
11095
get => _username;
@@ -118,19 +103,23 @@ public string Username
118103
}
119104
}
120105

121-
public string Domain
106+
private bool _isPasswordEmpty = true;
107+
108+
public bool IsPasswordEmpty
122109
{
123-
get => _domain;
110+
get => _isPasswordEmpty;
124111
set
125112
{
126-
if (value == _domain)
113+
if (value == _isPasswordEmpty)
127114
return;
128115

129-
_domain = value;
116+
_isPasswordEmpty = value;
130117
OnPropertyChanged();
131118
}
132119
}
133120

121+
private SecureString _password = new();
122+
134123
public SecureString Password
135124
{
136125
get => _password;
@@ -147,18 +136,57 @@ public SecureString Password
147136
}
148137
}
149138

150-
public bool IsPasswordEmpty
139+
private bool _adminSession;
140+
141+
public bool AdminSession
151142
{
152-
get => _isPasswordEmpty;
143+
get => _adminSession;
153144
set
154145
{
155-
if (value == _isPasswordEmpty)
146+
if (value == _adminSession)
156147
return;
157148

158-
_isPasswordEmpty = value;
149+
_adminSession = value;
159150
OnPropertyChanged();
160151
}
161152
}
153+
#endregion
154+
155+
#region Constructor
156+
157+
public RemoteDesktopConnectViewModel(Action<RemoteDesktopConnectViewModel> connectCommand,
158+
Action<RemoteDesktopConnectViewModel> cancelHandler, (string Name, string Host, bool AdminSession)? connectAsOptions = null)
159+
{
160+
ConnectCommand = new RelayCommand(_ => connectCommand(this));
161+
CancelCommand = new RelayCommand(_ => cancelHandler(this));
162+
163+
if (connectAsOptions == null)
164+
{
165+
HostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.RemoteDesktop_HostHistory);
166+
}
167+
else
168+
{
169+
ConnectAs = true;
170+
171+
UseCredentials = true;
172+
173+
Name = connectAsOptions.Value.Name;
174+
Host = connectAsOptions.Value.Host;
175+
176+
AdminSession = connectAsOptions.Value.AdminSession;
177+
}
178+
}
179+
180+
#endregion
181+
182+
#region Commands
183+
184+
public ICommand ConnectCommand { get; }
185+
186+
public ICommand CancelCommand { get; }
187+
#endregion
188+
189+
#region Methods
162190

163191
/// <summary>
164192
/// Check if the passwords are valid.
@@ -167,4 +195,5 @@ private void ValidatePassword()
167195
{
168196
IsPasswordEmpty = Password == null || Password.Length == 0;
169197
}
198+
#endregion
170199
}

Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public bool IsProfileFilterSet
205205

206206
private readonly GroupExpanderStateStore _groupExpanderStateStore = new();
207207
public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore;
208-
208+
209209
private bool _canProfileWidthChange = true;
210210
private double _tempProfileWidth;
211211

@@ -481,7 +481,7 @@ private void ClearProfileFilterAction()
481481
_searchDisabled = true;
482482
Search = string.Empty;
483483
_searchDisabled = false;
484-
484+
485485
foreach (var tag in ProfileFilterTags)
486486
tag.IsSelected = false;
487487

@@ -504,7 +504,7 @@ private void CollapseAllProfileGroupsAction()
504504
{
505505
SetIsExpandedForAllProfileGroups(false);
506506
}
507-
507+
508508
public ItemActionCallback CloseItemCommand => CloseItemAction;
509509

510510
private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
@@ -552,6 +552,8 @@ private async Task Connect(string host = null)
552552
sessionInfo.Password = instance.Password;
553553
}
554554

555+
sessionInfo.AdminSession = instance.AdminSession;
556+
555557
// Add to history
556558
// Note: The history can only be updated after the values have been read.
557559
// Otherwise, in some cases, incorrect values are taken over.
@@ -612,12 +614,19 @@ private async Task ConnectProfileAs()
612614
sessionInfo.Password = instance.Password;
613615
}
614616

617+
sessionInfo.AdminSession = instance.AdminSession;
618+
615619
Connect(sessionInfo, instance.Name);
616620
}, async _ =>
617621
{
618622
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
619623
ConfigurationManager.OnDialogClose();
620-
}, (profileInfo.Name, profileInfo.RemoteDesktop_Host));
624+
},
625+
(
626+
profileInfo.Name,
627+
profileInfo.RemoteDesktop_Host,
628+
true
629+
));
621630

622631
customDialog.Content = new RemoteDesktopConnectDialog
623632
{
@@ -659,7 +668,7 @@ private void SetIsExpandedForAllProfileGroups(bool isExpanded)
659668
foreach (var group in Profiles.Groups.Cast<CollectionViewGroup>())
660669
GroupExpanderStateStore[group.Name.ToString()] = isExpanded;
661670
}
662-
671+
663672
private void ResizeProfile(bool dueToChangedSize)
664673
{
665674
_canProfileWidthChange = false;

0 commit comments

Comments
 (0)