Entries Tagged as ‘C#’

March 14, 2008

Boxing/Unboxing in .NET

This post has been long overdue; I should have posted it two months back. Anyway, a couple of my friends attended training in .NET concepts sponsored by my company. They came back from the training and discussed with me the stuff they had learnt. One of the fellows mentioned that they had been taught that [...]

September 21, 2007

How to find the NetBIOS name of a domain

Following is the C# code needed to find the NetBIOS name of a domain from Active Directory:
using System;
using System.DirectoryServices;
void PrintNetBIOSName()
{
    string netBIOSName = null;
    DirectoryEntry rootDSE = new DirectoryEntry(
        ”LDAP://<server address>/rootDSE”,
        ”<username>”, “<password>”);
    string domain = (string)rootDSE.Properties[
        "defaultNamingContext"][0];
    if (!String.IsNullOrEmpty(domain))
    {
        DirectoryEntry parts = new DirectoryEntry(
            ”LDAP://<server address>/CN=Partitions
            ,CN=Configuration,” + domain,
            ”<username>”, “<password>”);
        foreach (DirectoryEntry part in parts.Children)
        {
            if ((string)part.Properties[
                "nCName"][0] == domain)
            {
                netBIOSName = (string)part.Properties[
                    "NetBIOSName"][0];
                break;
            }
        }
        Console.WriteLine(netBIOSName);
    }
}
REFERENCES:

http://home.hot.rr.com/graye/CodeSnippets.htm
Binding to Active Directory Domain Services [...]