Skip to content

Commit 5741d30

Browse files
committed
Feature: RDP admin session
1 parent cebd23b commit 5741d30

File tree

9 files changed

+220
-177
lines changed

9 files changed

+220
-177
lines changed

Source/NETworkManager.Profiles/GroupInfo.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System.Collections.Generic;
2-
using System.Security;
3-
using System.Xml.Serialization;
4-
using NETworkManager.Models.Network;
1+
using NETworkManager.Models.Network;
52
using NETworkManager.Models.PowerShell;
63
using NETworkManager.Models.PuTTY;
74
using NETworkManager.Models.RemoteDesktop;
85
using NETworkManager.Settings;
6+
using System.Collections.Generic;
7+
using System.Security;
8+
using System.Xml.Serialization;
99

1010
namespace NETworkManager.Profiles;
1111

@@ -37,7 +37,7 @@ public GroupInfo(GroupInfo group) : this(group.Name)
3737
{
3838
// General
3939
Description = group.Description;
40-
40+
4141
// Profiles
4242
Profiles = group.Profiles;
4343

@@ -46,6 +46,7 @@ public GroupInfo(GroupInfo group) : this(group.Name)
4646
RemoteDesktop_Username = group.RemoteDesktop_Username;
4747
RemoteDesktop_Domain = group.RemoteDesktop_Domain;
4848
RemoteDesktop_Password = group.RemoteDesktop_Password;
49+
RemoteDesktop_AdminSession = group.RemoteDesktop_AdminSession;
4950
RemoteDesktop_OverrideDisplay = group.RemoteDesktop_OverrideDisplay;
5051
RemoteDesktop_AdjustScreenAutomatically = group.RemoteDesktop_AdjustScreenAutomatically;
5152
RemoteDesktop_UseCurrentViewSize = group.RemoteDesktop_UseCurrentViewSize;
@@ -168,7 +169,7 @@ public GroupInfo(GroupInfo group) : this(group.Name)
168169
/// Name of the group.
169170
/// </summary>
170171
public string Name { get; set; }
171-
172+
172173
/// <summary>
173174
/// Description of the group.
174175
/// </summary>
@@ -183,6 +184,8 @@ public GroupInfo(GroupInfo group) : this(group.Name)
183184
public string RemoteDesktop_Domain { get; set; }
184185

185186
[XmlIgnore] public SecureString RemoteDesktop_Password { get; set; }
187+
188+
public bool RemoteDesktop_AdminSession { get; set; }
186189
public bool RemoteDesktop_OverrideDisplay { get; set; }
187190
public bool RemoteDesktop_AdjustScreenAutomatically { get; set; }
188191

Source/NETworkManager.Profiles/ProfileInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public ProfileInfo(ProfileInfo profile)
8282
RemoteDesktop_Username = profile.RemoteDesktop_Username;
8383
RemoteDesktop_Domain = profile.RemoteDesktop_Domain;
8484
RemoteDesktop_Password = profile.RemoteDesktop_Password;
85+
RemoteDesktop_AdminSession = profile.RemoteDesktop_AdminSession;
8586
RemoteDesktop_OverrideDisplay = profile.RemoteDesktop_OverrideDisplay;
8687
RemoteDesktop_AdjustScreenAutomatically = profile.RemoteDesktop_AdjustScreenAutomatically;
8788
RemoteDesktop_UseCurrentViewSize = profile.RemoteDesktop_UseCurrentViewSize;
@@ -314,6 +315,8 @@ public ProfileInfo(ProfileInfo profile)
314315
public string RemoteDesktop_Domain { get; set; }
315316

316317
[XmlIgnore] public SecureString RemoteDesktop_Password { get; set; }
318+
319+
public bool RemoteDesktop_AdminSession { get; set; }
317320
public bool RemoteDesktop_OverrideDisplay { get; set; }
318321
public bool RemoteDesktop_AdjustScreenAutomatically { get; set; }
319322

Source/NETworkManager/ProfileDialogManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private static ProfileInfo ParseProfileInfo(ProfileViewModel instance)
9191
RemoteDesktop_Password = instance.RemoteDesktop_UseCredentials
9292
? instance.RemoteDesktop_Password
9393
: new SecureString(), // Remove sensitive info on disable
94+
RemoteDesktop_AdminSession = instance.RemoteDesktop_AdminSession,
9495
RemoteDesktop_OverrideDisplay = instance.RemoteDesktop_OverrideDisplay,
9596
RemoteDesktop_AdjustScreenAutomatically = instance.RemoteDesktop_AdjustScreenAutomatically,
9697
RemoteDesktop_UseCurrentViewSize = instance.RemoteDesktop_UseCurrentViewSize,
@@ -317,6 +318,7 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance)
317318
RemoteDesktop_Password = instance.RemoteDesktop_UseCredentials
318319
? instance.RemoteDesktop_Password
319320
: new SecureString(), // Remove sensitive info on disable
321+
RemoteDesktop_AdminSession = instance.RemoteDesktop_AdminSession,
320322
RemoteDesktop_OverrideDisplay = instance.RemoteDesktop_OverrideDisplay,
321323
RemoteDesktop_AdjustScreenAutomatically = instance.RemoteDesktop_AdjustScreenAutomatically,
322324
RemoteDesktop_UseCurrentViewSize = instance.RemoteDesktop_UseCurrentViewSize,

Source/NETworkManager/ViewModels/GroupViewModel.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using System;
1+
using NETworkManager.Models.Network;
2+
using NETworkManager.Models.PowerShell;
3+
using NETworkManager.Models.PuTTY;
4+
using NETworkManager.Models.RemoteDesktop;
5+
using NETworkManager.Profiles;
6+
using NETworkManager.Utilities;
7+
using System;
28
using System.Collections.Generic;
39
using System.ComponentModel;
410
using System.Linq;
511
using System.Security;
612
using System.Windows.Data;
713
using System.Windows.Input;
8-
using NETworkManager.Models.Network;
9-
using NETworkManager.Models.PowerShell;
10-
using NETworkManager.Models.PuTTY;
11-
using NETworkManager.Models.RemoteDesktop;
12-
using NETworkManager.Profiles;
13-
using NETworkManager.Utilities;
1414

1515
// ReSharper disable InconsistentNaming
1616

@@ -166,6 +166,21 @@ public SecureString RemoteDesktop_Password
166166
}
167167
}
168168

169+
private bool _remoteDesktop_AdminSession;
170+
171+
public bool RemoteDesktop_AdminSession
172+
{
173+
get => _remoteDesktop_AdminSession;
174+
set
175+
{
176+
if (value == _remoteDesktop_AdminSession)
177+
return;
178+
179+
_remoteDesktop_AdminSession = value;
180+
OnPropertyChanged();
181+
}
182+
}
183+
169184
private bool _remoteDesktop_OverrideDisplay;
170185

171186
public bool RemoteDesktop_OverrideDisplay
@@ -1793,6 +1808,7 @@ public GroupViewModel(Action<GroupViewModel> saveCommand, Action<GroupViewModel>
17931808
RemoteDesktop_Username = groupInfo.RemoteDesktop_Username;
17941809
RemoteDesktop_Domain = groupInfo.RemoteDesktop_Domain;
17951810
RemoteDesktop_Password = groupInfo.RemoteDesktop_Password;
1811+
RemoteDesktop_AdminSession = groupInfo.RemoteDesktop_AdminSession;
17961812
RemoteDesktop_OverrideDisplay = groupInfo.RemoteDesktop_OverrideDisplay;
17971813
RemoteDesktop_AdjustScreenAutomatically = groupInfo.RemoteDesktop_AdjustScreenAutomatically;
17981814
RemoteDesktop_UseCurrentViewSize = groupInfo.RemoteDesktop_UseCurrentViewSize;
@@ -1900,18 +1916,16 @@ public GroupViewModel(Action<GroupViewModel> saveCommand, Action<GroupViewModel>
19001916
// SNMP
19011917
SNMP_OverrideOIDAndMode = groupInfo.SNMP_OverrideOIDAndMode;
19021918
SNMP_OID = groupInfo.SNMP_OID;
1903-
SNMP_Modes = new List<SNMPMode> { SNMPMode.Get, SNMPMode.Walk, SNMPMode.Set };
1919+
SNMP_Modes = [SNMPMode.Get, SNMPMode.Walk, SNMPMode.Set];
19041920
SNMP_Mode = SNMP_Modes.FirstOrDefault(x => x == groupInfo.SNMP_Mode);
19051921
SNMP_OverrideVersionAndAuth = groupInfo.SNMP_OverrideVersionAndAuth;
19061922
SNMP_Versions = Enum.GetValues(typeof(SNMPVersion)).Cast<SNMPVersion>().ToList();
19071923
SNMP_Version = SNMP_Versions.FirstOrDefault(x => x == groupInfo.SNMP_Version);
19081924
SNMP_Community = groupInfo.SNMP_Community;
1909-
SNMP_Securities = new List<SNMPV3Security>
1910-
{ SNMPV3Security.NoAuthNoPriv, SNMPV3Security.AuthNoPriv, SNMPV3Security.AuthPriv };
1925+
SNMP_Securities = [SNMPV3Security.NoAuthNoPriv, SNMPV3Security.AuthNoPriv, SNMPV3Security.AuthPriv];
19111926
SNMP_Security = SNMP_Securities.FirstOrDefault(x => x == groupInfo.SNMP_Security);
19121927
SNMP_Username = groupInfo.SNMP_Username;
1913-
SNMP_AuthenticationProviders = Enum.GetValues(typeof(SNMPV3AuthenticationProvider))
1914-
.Cast<SNMPV3AuthenticationProvider>().ToList();
1928+
SNMP_AuthenticationProviders = [.. Enum.GetValues(typeof(SNMPV3AuthenticationProvider)).Cast<SNMPV3AuthenticationProvider>()];
19151929
SNMP_AuthenticationProvider =
19161930
SNMP_AuthenticationProviders.FirstOrDefault(x => x == groupInfo.SNMP_AuthenticationProvider);
19171931
SNMP_Auth = groupInfo.SNMP_Auth;

Source/NETworkManager/ViewModels/ProfileViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ProfileViewModel(Action<ProfileViewModel> saveCommand, Action<ProfileView
5757
Groups.SortDescriptions.Add(new SortDescription());
5858

5959
TagsCollection = new ObservableSetCollection<string>(profileInfo.TagsCollection);
60-
60+
6161
Tags = CollectionViewSource.GetDefaultView(TagsCollection);
6262
Tags.SortDescriptions.Add(new SortDescription("", ListSortDirection.Ascending));
6363

@@ -121,6 +121,7 @@ public ProfileViewModel(Action<ProfileViewModel> saveCommand, Action<ProfileView
121121
RemoteDesktop_Username = profileInfo.RemoteDesktop_Username;
122122
RemoteDesktop_Domain = profileInfo.RemoteDesktop_Domain;
123123
RemoteDesktop_Password = profileInfo.RemoteDesktop_Password;
124+
RemoteDesktop_AdminSession = profileInfo.RemoteDesktop_AdminSession;
124125
RemoteDesktop_OverrideDisplay = profileInfo.RemoteDesktop_OverrideDisplay;
125126
RemoteDesktop_AdjustScreenAutomatically = profileInfo.RemoteDesktop_AdjustScreenAutomatically;
126127
RemoteDesktop_UseCurrentViewSize = profileInfo.RemoteDesktop_UseCurrentViewSize;
@@ -1076,6 +1077,21 @@ public SecureString RemoteDesktop_Password
10761077
}
10771078
}
10781079

1080+
private bool _remoteDesktop_AdminSession;
1081+
1082+
public bool RemoteDesktop_AdminSession
1083+
{
1084+
get => _remoteDesktop_AdminSession;
1085+
set
1086+
{
1087+
if (value == _remoteDesktop_AdminSession)
1088+
return;
1089+
1090+
_remoteDesktop_AdminSession = value;
1091+
OnPropertyChanged();
1092+
}
1093+
}
1094+
10791095
private bool _remoteDesktop_OverrideDisplay;
10801096

10811097
public bool RemoteDesktop_OverrideDisplay

Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ private void ConnectProfileAsAction()
408408

409409
private void ConnectProfileExternalAction()
410410
{
411-
Process.Start("mstsc.exe", $"/V:{SelectedProfile.RemoteDesktop_Host}");
411+
var args = new List<string>();
412+
413+
if (SelectedProfile.RemoteDesktop_AdminSession)
414+
args.Add("/admin");
415+
416+
args.Add($"/V:{SelectedProfile.RemoteDesktop_Host}");
417+
418+
Process.Start("mstsc.exe", args);
412419
}
413420

414421
public ICommand AddProfileCommand => new RelayCommand(_ => AddProfileAction());
@@ -630,7 +637,7 @@ private Task ConnectProfileAs()
630637
(
631638
profileInfo.Name,
632639
profileInfo.RemoteDesktop_Host,
633-
true
640+
profileInfo.RemoteDesktop_AdminSession
634641
));
635642

636643
childWindow.Title = Strings.ConnectAs;

0 commit comments

Comments
 (0)