Вы можете использовать System.DirectoryServices пространство имен для выполнения задач такого типа (DirectoryServices - управляемая оболочка для LDAP).
Try
' Bind to the users container.
Dim entry As New
DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com")
' Create a DirectorySearcher object.
Dim mySearcher As New DirectorySearcher(entry)
' Create a SearchResultCollection object to hold a collection
' of SearchResults returned by the FindAll method.
Dim result As SearchResultCollection = mySearcher.FindAll()
' Create an object to hold a single result from the
' result collection.
Dim resEnt1 As SearchResult
' Get search results. For more information,
' see Getting Search Results.
'
' This sample uses Try...Catch to catch errors.
' Create an Exception object. For more information,
' see System.Exception.
Catch Exception1 As System.Runtime.InteropServices.COMException
Console.WriteLine(Exception1.Message)
Catch Exception2 As InvalidOperationException
Console.WriteLine(Exception2.Message)
Catch Exception3 As NotSupportedException
Console.WriteLine(Exception3.Message)
End Try
Вы можете использовать строку поиска , например, от "(&(objectCategory=user)(objectClass=person)(sAMAccountName=" + userId + "))"
до поиск пользователя (идентификатор пользователя должен быть заменен идентификатором пользователя).
Чтобы связать все это вместе, вы можете изменить приведенный ниже фрагмент, чтобы вернуть все свойства для пользователя. Затем вы можете настроить его так, чтобы фокусироваться только на имени пользователя.
Dim results As SearchResultCollection = Nothing
Try
' Bind to the users container.
Dim path As String = "LDAP://CN=users,DC=fabrikam,DC=com"
path = "LDAP://CN=Users,DC=strohmadom,DC=nttest,DC=microsoft,DC=com"
Dim entry As New DirectoryEntry(path)
' Create a DirectorySearcher object.
Dim mySearcher As New DirectorySearcher(entry)
' Set a filter for users with the name test.
mySearcher.Filter = "(&(objectClass=user)(anr=test*))"
' Use the FindAll method to return objects to a SearchResultCollection.
results = mySearcher.FindAll()
' Iterate through each SearchResult in the SearchResultCollection.
Dim searchResult As SearchResult
For Each searchResult In results
' Display the path of the object found.
Console.WriteLine("Search properties for {0}", _
searchResult.Path)
' Iterate through each property name in each SearchResult.
Dim propertyKey As String
For Each propertyKey In searchResult.Properties.PropertyNames
' Retrieve the value assigned to that property name
' in the ResultPropertyValueCollection.
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
' Handle results. Be aware that the following
' WriteLine() only returns readable results for
' properties that are strings.
Console.WriteLine("{0}:{1}", _
propertyKey, _
propertyValue.ToString())
Next propertyValue
Next propertyKey
Next searchResult
Finally
' To prevent memory leaks, always call
' SearchResultCollection.Dispose() manually.
If Not results Is Nothing Then
results.Dispose()
results = Nothing
End If
End Try