Jamesies random blog

A blog of randomness! Anything interesting I do or find, I'll try and post here!

Tuesday, August 28, 2007

Building an LDAP domain path for AD queries in C# .NET

Little task I had to do this morning I thought I'd share.
I'm knocking up something that will do some active directory queries, and the first step was to connect using the LDAP Path. I wanted this to be fairly automated though, and the following code will work out the domain of the local machine and build the LDAP string for you. Might be of use... :)

String DNSDomainName = Dns.GetHostEntry(Dns.GetHostName()).HostName;

private void GetUsersFromAD()
{
String DNSDomainName = Dns.GetHostEntry(Dns.GetHostName()).HostName;
DirectoryEntry de = new DirectoryEntry();
String[] DNSComponents = DNSDomainName.Split('.');
String LDAPPath = "LDAP://OU=Domain";
for (int i = 1; i < DNSComponents.Length; i++)
{
LDAPPath = LDAPPath + ",DC=" + DNSComponents[i].ToString();
}
de.Path = LDAPPath;

}

Thursday, August 23, 2007

Italian Lakes, Lake Garda pictures

We recently visited Lake Garda on our hols. I've uploaded some photos to the website, so why not take a look? Pictures from Lake Garda

Wednesday, August 22, 2007

Result

Today I replaced a motherboard in a Dell laptop and had NO screws left over! AND it works!