Sunday, January 11, 2009

Get Active Directory Connection String

1- create new C# windows application
2- Put Text Box on the Form
3- on Form load Event Copy the Below Code:

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(
textBox1.Text = adsPath;
4- don't forget to make using System.DirectoryServices;
- Add Reference for System.DirectoryServices
5- you must run the application On a machine has a domain