.NET Active Directory Wrapper

   Access Active Directory From Your Code

View DotNet Active Directory Wrapper Plus Demo
 

Active Directory
Introduction
Objects
Object Properties

DirectoryServices Namespace
Introduction
DirectoryEntry Class

How to .. in C# .NET
Create User
Disable User
Enable User
Authenticate a User
Change User Password
Get DirectoryEntry of a user
Get Users in a Group
Get Object Property

Other Resources
References

Getting the DirectoryEntry Object from Active Directory for a given username

public static DirectoryEntry GetUser(string UserName)
{
//create an instance of the DirectoryEntry
DirectoryEntry de = GetDirectoryObject("/" + GetLDAPDomain());

//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher(de);

deSearch.SearchRoot =de;
//set the search filter
deSearch.Filter = "(&(objectCategory=user)(cn=" + UserName + "))";
//deSearch.SearchScope = SearchScope.Subtree;

//find the first instance
SearchResult results= deSearch.FindOne();

//if found then return, otherwise return Null
if(results !=null)
{
//de= new DirectoryEntry(results.Path,ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//if so then return the DirectoryEntry object
return results.GetDirectoryEntry();
}
else
{
return null;
}
}