I’m looking for a way to find Active Directory on the network (probably thru DNS/DHCP settings assigned) and then trying to access it, getting all the things like AD servername, BaseDN or domain name from within a code without asking user to provide information about his network. Is there a way to go?
private string strADServerName = "SERVERAD";
private string strBaseDN = "DC=DOMAIN,DC=COM";
private string strAccountFilter = "sAMAccountName";
private string domainName = "DOMAIN";
When you install a Active-Directory you need a Dynamic DNS (DDNS). During his installation AD registers information in the DNS, as you can see in the following capture. On a given Windows computer the WMI class
win32_ComputerSystemcan provide you the domain name.You can see here under the detail of
_ldapentry :This
SRVentry provide DNS address and port of the domain controllers of your domain._ldapentry can have multiple values as you’ve got multiple domain controllers in your domain.Using
NSLOOKUP.EXEtool, you can get this information as shown here under :If you don’t know the domain you can just query for
_ldap._tcplike in the sample above :On the C# point of view, I am not sure that the class
System.Net.DNSallow you to query SRV records. You can find in this codeplex entry DnDNS assembly seems to do it.