Good day! This is how I search Active Directory
Public Sub UserList(domain As String)
Try
Using context = New PrincipalContext(ContextType.Domain, domain)
Dim userPrin As New UserPrincipal(context) With {
.Enabled = True}
Using searcher = New PrincipalSearcher(New UserPrincipal(context))
searcher.QueryFilter = userPrin
For Each result In searcher.FindAll()
Dim de As DirectoryEntry = TryCast(result.GetUnderlyingObject(), DirectoryEntry)
Dim dn1 As String = de.Properties("cn").Value
DataGridView1.Rows.Add(dn1)
Next result
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Tell me how you can specify, in addition to the domain, also the username and password of the administrator?
This line indicates the domain and the path to the container in which the search is performed
Using context = New PrincipalContext(ContextType.Domain, domain, OU)