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(
"LDAP://{0}/{1}",
server,
dnc
);
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
Very nice article man.. keep it going and don't stop go go go :)
ReplyDeleteThanks a lot. Worked like a charm :-) Always used to get the connection string wrong!
ReplyDeleteThanks a lot, nice app ;)
ReplyDeleteAwesome piece of code! Thank you!
ReplyDeleteand four years later... it worked like a charm, too! i was skeptical at first when i saw the "rootDSE" thing, but then learned much more about it from the Windows Dev Center site.
ReplyDeletethanks man, your tips and tricks are simple, yet very useful.
(Antony)