This is an exmple from a previous post. Take a look at the other posts,
there are a lot of questions about system.directoryservices. If you have
more specific questions post them and we can help further.
Jared
Sub GetInfo(ByVal UserName As String) 'User name - NOT display name
Dim Entry As New DirectoryEntry("LDAP://RootDSE")
Dim DomainPath As String = "LDAP://" &
Entry.Properties("defaultNamingContext").Value
Dim Results As SearchResultCollection, Result As SearchResult
'Domain Naming Context
'DC=MyDomain,DC=com
Entry = New DirectoryEntry(DomainPath)
Dim Searcher As New DirectorySearcher(Entry)
With Searcher
.SearchScope = SearchScope.Subtree
.Filter = "(&(objectClass=person)(sAMAccountName=" & UserName &
"))"
'Only works when threaded. Keep this in mind.
'Default size returned is 1000 (server set)
.PageSize = 100
.PropertiesToLoad.AddRange(New String() {"sAMAccountName",
"displayName"})
Result = .FindOne
End With
If Not Result Is Nothing Then
'Watch for multivalued properties
If TypeOf Result.GetDirectoryEntry.Properties("displayName") Is
System.Array Then
MessageBox.Show(Result.GetDirectoryEntry.Propertie s("displayName")(0).Value)
Else
MessageBox.Show(Result.GetDirectoryEntry.Propertie s("displayName").Value)
End If
End If
With Searcher
'You can use wild cards, Look up the RFC on LDAP for more info
.Filter = "(&(objectClass=person)(sAMAccountName=" & UserName &
"*))"
Results = Searcher.FindAll
End With
For Each Result In Results
'Same as before
If TypeOf Result.GetDirectoryEntry.Properties("displayName") Is
System.Array Then
Console.WriteLine(Result.GetDirectoryEntry.Propert ies("displayName")(0).Value)
Else
Console.WriteLine(Result.GetDirectoryEntry.Propert ies("displayName").Value)
End If
Next
End Sub
"DotNetJunkies User" <User@-NOSPAM-DotNetJunkies.com> wrote in message
news:uM**************@tk2msftngp13.phx.gbl...
Does anyone know how to get the user information such as Name, Address,
Email, Phone Number, etc from Windows Active Directory? The samples I have
seen so far donâ?Tt get the User Address, Email, or Phone Number! Thanks.
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup
engine supports Post Alerts, Ratings, and Searching.