getting user names out of AD

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I'm trying to get all the user names of users out of an active directory so
they can be put into a database, but when i run the code below it gives
nothing back, if i change username to just name it gives me the full name of
the user, but not the user name... what is going wrong? thanks



Dim entry As New DirectoryEntry("LDAP://reschini")

Dim mySearcher As New DirectorySearcher(entry)

mySearcher.Filter = "(objectClass=user)"

Dim resEnt As SearchResult

For Each resEnt In mySearcher.FindAll

Try

Me.ListBox1.Items.Add(resEnt.GetDirectoryEntry.Username)

Catch ex As Exception

End Try



Next
 
Dim entry As New DirectoryEntry "LDAP://reschini")
Dim mySearcher As New DirectorySearcher(entry)
mySearcher.PropertiesToLoad.Add("cn")
mySearcher.Filter = "(objectclass=user)"
Dim resEnt As SearchResult

For Each resEnt In mySearcher.FindAll
If Not IsNothing(resEnt.Properties("cn")) Then
Me.ListBox1.Items.Add(resEnt.Properties
("cn")(0))
End If
Next

I took out the try in order to catch the errors, but this
should work. I think the Username is used when
Authenicating users. Hope this helps
 
Back
Top