Snippet to obtain Active Directory Path

Last post 06-26-2009 5:34 PM by StevenSw. 2 replies.

Sort Posts:

  • Snippet to obtain Active Directory Path

    06-13-2009, 10:47 PM
    • Participant
      1,410 point Participant
    • StevenSw
    • Member since 08-19-2002, 4:04 PM
    • Opelika, AL
    • Posts 278

    Sumply return the path of AD when executed on a domain.

    public string ActiveDirectoryPath()
    {
    	DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
    	using (root)
    	{
    		string dnc = root.Properties["defaultNamingContext"][0].ToString();
    		string server = root.Properties["dnsHostName"][0].ToString();
    		string adsPath = String.Format("LDAP://{0}/{1}", server, dnc);
    		return adsPath;
    	}
    }
     
    Steven M. Swafford
    http://radicaldevelopment.net

    Dont forget to click "Mark as Answer" on the post that helped you.
  • Re: Snippet to obtain Active Directory Path

    06-25-2009, 3:29 PM
    • Member
      38 point Member
    • wildquaker
    • Member since 12-21-2008, 5:49 PM
    • Philippines
    • Posts 10

    In a using code block eh? Is an object with a DirectoryEntry type disposable?

  • Re: Snippet to obtain Active Directory Path

    06-26-2009, 5:34 PM
    • Participant
      1,410 point Participant
    • StevenSw
    • Member since 08-19-2002, 4:04 PM
    • Opelika, AL
    • Posts 278
    Steven M. Swafford
    http://radicaldevelopment.net

    Dont forget to click "Mark as Answer" on the post that helped you.
Page 1 of 1 (3 items)