Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

How can I locate what domain a domain controller is in?

Last post 01-17-2010, 4:36 PM by mliben. 1 replies.
Sort Posts: Previous Next
  •  01-15-2010, 6:11 PM 7728

    How can I locate what domain a domain controller is in?

    I'm in domain A and I have the name of a DC that could be in domain B or C, I want to return the domain name, any suggestions of how I would code this?

    Many thanks
  •  01-17-2010, 4:36 PM 7730 in reply to 7728

    Re: How can I locate what domain a domain controller is in?

    The are multiple ways to do this depending on whether you want the DNS name, the NetBIOS name or both.

    Quick and dirty to get the DNS name is to connect to the domain controller with a search base of an empty string and searchScope of Base. Read the dnsHostname attribute. Remove everything up to and including the first period and you are left with the DNS domain of the domain controller.

    If you want the DNS name and the NetBIOS name, you need to de a little more work. Connect to the domain controller with a search base of an empty string and searchScope of Base, read the configurationNamingContext and defaultNamingContext attributes. Set the value in the configurationNamingContext as the search base and the filter to (&(objectClass=crossRef)(nCName=value of defaultNamingContext)) and read the value of the nETBIOSName attribute for the short name and the dnsRoot attribute for the DNS domain name.

     

     

View as RSS news feed in XML