Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am new to programming(VB.NET) and need help to get list of all Domain names from LDAP from my project.
I am able to retrieve other details like First Name, Surname, Mail, etc...but cant get domain names. I tried many options online but none worked for me. I just need the list of domains so I can loop it further and continue with other process.
Help would be much appreciated.

Best Regards.

What I have tried:

I have used the below code to match other details Environment.UserDomainName gives me my domain, but I need domain for other users as well.


dirEntry = New System.DirectoryServices.DirectoryEntry("LDAP://" & " & Environment.UserDomainName & ")
dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
dirSearcher.Filter = "(samAccountName= " & txt_Usr_ID.Text & ")"
dirSearcher.PropertiesToLoad.Add("GivenName")
dirSearcher.PropertiesToLoad.Add("sn")
dirSearcher.PropertiesToLoad.Add("mail")
Str_Searchres = dirSearcher.FindOne()
Dir_direntry = Str_Searchres.GetDirectoryEntry()
Str_Usr_ID = txt_Usr_ID.Text
Str_Fname = Dir_direntry.Properties("GivenName").Value.ToString()
Str_Lname = Dir_direntry.Properties("sn").Value.ToString()
Str_Mail = Dir_direntry.Properties("mail").Value.ToString()
Posted
Updated 8-Aug-18 2:57am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900