getting user names out of AD

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top