This first approach may be too simplistic, but you should be able to tell the domain name by going into SYSTEM PROPERTIES via MyComputer or Network properties.
Else, here is a method I found on line at
Find the NetBios Name of a domain in AD
Its been quite a bit of struggle for me to find an accurate way of finding the netbios name of a domain from AD using System.DirectoryServices.
In case you are in the same jam here how you do it.
- Connect to AD using the following ldap url: LDAP://CN=Partitions,CN=Configuration,DC=,DC=<local|com>
- When querying AD using the Directory Searcher object uses the following filter: netbiosname=*
This should give you a record from AD containing the netbios name of the domain as the CN
AD stores the the netbios name in the Partitions naming container which is stored inside the configuration naming container.
A more detailed explanation and more samples can be found in the Active Directory Cookbook or its online version
// Method call
string netBiosName = GetNetBiosName( LDAP://CN=Partitions,CN=Configuration,DC=,DC=<local|com>, “<userName”", “”);
// Method call
// Method Definition
private string GetNetBiosName(
string netbiosName = string.Empty;
DirectoryEntry dirEntry = new DirectoryEntry(ldapUrl,
DirectorySearcher searcher = new DirectorySearcher(dirEntry);
searcher.Filter = “netbiosname=*”;
SearchResultCollection results = searcher.FindAll();
if (results.Count > 0)
ResultPropertyValueCollection rpvc = results.Properties[“CN”];
netbiosName = rpvc.ToString();
Crossposted from tariqayad.com