22Imports System.Net.NetworkInformation
33Imports Microsoft.VisualBasic.ControlChars
44Imports System.Text.RegularExpressions
5+ Imports System.DirectoryServices.AccountManagement
56
67Public Class ADDSJoinDialog
78
@@ -65,6 +66,9 @@ Public Class ADDSJoinDialog
6566
6667 Private NtLogonPathStart As String = ""
6768
69+ Private userMappings As Dictionary( Of String , List( Of Principal))
70+ Private initialUserName As String = ""
71+
6872 Private Sub Cancel_Button_Click(sender As Object , e As EventArgs) Handles Cancel_Button.Click
6973 DialogResult = Windows.Forms.DialogResult.Cancel
7074 Close()
@@ -74,6 +78,8 @@ Public Class ADDSJoinDialog
7478 BackColor = CurrentTheme.SectionBackgroundColor
7579 ForeColor = CurrentTheme.ForegroundColor
7680 ComboBox1.BackColor = BackColor
81+ ComboBox2.BackColor = BackColor
82+ ComboBox3.BackColor = BackColor
7783 TextBox1.BackColor = BackColor
7884 TextBox2.BackColor = BackColor
7985 TextBox3.BackColor = BackColor
@@ -83,6 +89,8 @@ Public Class ADDSJoinDialog
8389 GroupBox1.BackColor = BackColor
8490 RichTextBox1.BackColor = BackColor
8591 ComboBox1.ForeColor = ForeColor
92+ ComboBox2.ForeColor = ForeColor
93+ ComboBox3.ForeColor = ForeColor
8694 TextBox1.ForeColor = ForeColor
8795 TextBox2.ForeColor = ForeColor
8896 TextBox3.ForeColor = ForeColor
@@ -97,6 +105,8 @@ Public Class ADDSJoinDialog
97105 ChangePage(WizardPage.DnsConfigPage)
98106 dnsMappings.Clear()
99107 ComboBox1.Items.Clear()
108+ ComboBox2.Items.Clear()
109+ ComboBox3.Items.Clear()
100110 Visible = True
101111 ADDSInitBW.RunWorkerAsync()
102112 Do Until Not ADDSInitBW.IsBusy
@@ -116,18 +126,30 @@ Public Class ADDSJoinDialog
116126 dsIsInDomain = DomainServicesModule.DSIsInDomain()
117127 If dsIsInDomain Then
118128 ProgressReporter.SetMessage( "Getting name of assigned domain..." )
119- ADDSInitBW.ReportProgress( 25 )
129+ ADDSInitBW.ReportProgress( 20 )
120130 dsDomainName = DomainServicesModule.DSGetDomainName()
121131 End If
122132 ProgressReporter.SetMessage( "Getting network adapters..." )
123- ADDSInitBW.ReportProgress( 50 )
133+ ADDSInitBW.ReportProgress( 40 )
124134 GetNetworkAdapters()
125135 ProgressReporter.SetMessage( "Getting DNS addresses for each network adapter..." )
126- ADDSInitBW.ReportProgress( 75 )
136+ ADDSInitBW.ReportProgress( 60 )
127137 GetDnsAddresses()
128138 ProgressReporter.SetMessage( "Getting primary domain controller NetBIOS name..." )
129- ADDSInitBW.ReportProgress( 88 )
139+ ADDSInitBW.ReportProgress( 80 )
130140 NtLogonPathStart = DomainServicesModule.DSGetDomainControllerNetBIOSName()
141+ If dsIsInDomain Then
142+ ProgressReporter.SetMessage( "Mapping organizational units and users..." )
143+ ADDSInitBW.ReportProgress( 90 )
144+ userMappings = DomainServicesModule.DSMapOrganizationalUnitsAndUsers(dsDomainName, NtLogonPathStart)
145+ If userMappings IsNot Nothing Then
146+ ComboBox2.Items.AddRange(userMappings.Keys.ToArray())
147+ ComboBox2.SelectedIndex = 0
148+ End If
149+ Else
150+ DomainAutoUserPanel.Enabled = False
151+ RadioButton3.Enabled = False
152+ End If
131153 ProgressReporter.SetMessage( "Initialization complete." )
132154 ADDSInitBW.ReportProgress( 100 )
133155 End Sub
@@ -257,7 +279,7 @@ Public Class ADDSJoinDialog
257279 DialogResult = Windows.Forms.DialogResult.None
258280 Exit Sub
259281 Else
260- dsInfo = New DomainInformation(TextBox4.Text, TextBox5.Text , TextBox6.Text)
282+ dsInfo = New DomainInformation(TextBox4.Text, initialUserName , TextBox6.Text)
261283 End If
262284 If ApplyDsSettings() Then
263285 MsgBox( "Domain settings were added successfully to the answer file. You can further modify these components in the System components section." )
@@ -464,5 +486,28 @@ Public Class ADDSJoinDialog
464486 Private Sub TextBox5_TextChanged(sender As Object , e As EventArgs) Handles TextBox5.TextChanged
465487 AddsUpnPathText.Text = String .Format( "{0}@{1}" , TextBox5.Text, TextBox4.Text)
466488 AddsNtLogonPathText.Text = String .Format( "{0}\{1}" , NtLogonPathStart, TextBox5.Text)
489+ initialUserName = TextBox5.Text
490+ End Sub
491+
492+ Private Sub RadioButton3_CheckedChanged(sender As Object , e As EventArgs) Handles RadioButton3.CheckedChanged
493+ DomainAutoUserPanel.Enabled = RadioButton3.Checked
494+ TextBox5.Enabled = Not RadioButton3.Checked
495+ TextBox4.Enabled = Not RadioButton3.Checked
496+ End Sub
497+
498+ Private Sub ComboBox2_SelectedIndexChanged(sender As Object , e As EventArgs) Handles ComboBox2.SelectedIndexChanged
499+ Try
500+ ComboBox3.Items.Clear()
501+ ComboBox3.Items.AddRange(userMappings(ComboBox2.SelectedItem).Select( Function (adUser) adUser.DisplayName).ToArray())
502+ ComboBox3.SelectedIndex = 0
503+ Catch ex As Exception
504+
505+ End Try
506+ End Sub
507+
508+ Private Sub ComboBox3_SelectedIndexChanged(sender As Object , e As EventArgs) Handles ComboBox3.SelectedIndexChanged
509+ AddsUpnPathText.Text = String .Format( "{0}@{1}" , userMappings(ComboBox2.SelectedItem)(ComboBox3.SelectedIndex).SamAccountName, TextBox4.Text)
510+ AddsNtLogonPathText.Text = String .Format( "{0}\{1}" , NtLogonPathStart, userMappings(ComboBox2.SelectedItem)(ComboBox3.SelectedIndex).SamAccountName)
511+ initialUserName = userMappings(ComboBox2.SelectedItem)(ComboBox3.SelectedIndex).SamAccountName
467512 End Sub
468513End Class
0 commit comments