1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
Private Sub bwDisplayUsers_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bwDisplayUsers.DoWork
Try
Dim objEntry As New DirectoryEntry(txtServer.Text, txtUsername.Text, txtPassword.Text, AuthenticationTypes.Secure)
' Set up to search for UserMan on the Users node
Dim objSearcher As New DirectorySearcher(objEntry)
objSearcher.Filter = txtFilter.Text
objSearcher.SearchScope = SearchScope.Subtree
objSearcher.PageSize = txtPageSize.Text
Dim objSearchResult As SearchResultCollection
' Find the user
objSearchResult = objSearcher.FindAll()
userlist = New ArrayList
For Each searchResult In objSearchResult
' Iterate through each property name in each SearchResult.
Dim propertyKey As Object
For Each propertyKey In searchResult.Properties.PropertyNames
Dim valueCollection As ResultPropertyValueCollection = searchResult.Properties(propertyKey)
' Iterate through values for each property name in each SearchResult.
Dim propertyValue As Object
For Each propertyValue In valueCollection
If propertyKey = "cn" Then
givenName = propertyValue.ToString()
End If
If propertyKey = "samaccountname" Then
uid = propertyValue.ToString()
End If
If propertyKey = "sn" Then
sn = propertyValue.ToString()
End If
If propertyKey = "legacyexchangedn" Then
objdistname = propertyValue.ToString()
End If
If propertyKey = "cn" Then
cn = propertyValue.ToString()
End If
If propertyKey = "mail" Then
mail = propertyValue.ToString()
End If
If propertyKey = "adspath" Then
adpath = propertyValue.ToString()
End If
If propertyKey = "nETBIOSName" Then
dc = propertyValue.ToString()
End If
Next propertyValue
Next propertyKey
Dim user As String() = New String() {uid, givenName, sn, txtServer.Text.Split("/")(2), mail, adpath, objdistname, 0}
userlist.Add(user)
sn = ""
cn = ""
mail = ""
adpath = ""
givenName = ""
uid = ""
Next searchResult
Catch ex As Exception
MsgBox(ex.Message, vbCritical, "Erreur3")
tLoadUsers.Enabled = False
End Try
End Sub |
Partager