Introduction
The goal of the application was to build a users management assistant application for any organization working with Microsoft Active Directory Services:
- IT Managers – Get self customized reports and Information in a better friendly way
- IT Workers – Verify data inserted in users and groups objects, make updates to the active directory and get self customized reports
Background
It is part of college final project.
Prerequisites
- Framework 3.5 installed on the computer (can be downloaded from Microsoft web site)
- Connection to Microsoft Active Directory
- Microsoft Office Excel installed (97 and up)
- Microsoft SQL server 2005 installed in the organization
- Can also be done by "ini" files instead of DB
- Microsoft patterns & practices Version=4.1.0.0 is needed to be installed in dev computer
Using the Application
Step 1 Install the DB (MSSQL)
Open Microsoft-SQL 2005 and restore database from EmptyDB.bak (which is in the zip file).
Step 2 Run the Program
- Compile and run the program (
DirectoryGate
project) - Choose the DB server which you installed the DB in.
- Click on the "Add - Edit Domain List" button and set the Domain
- Start to query/update/delete your Active Directory
- The results are in Excel file in your application folder
About the Code
The solution is separated into 6 projects:
ActiveDirectoryDO
- static
class handles all the active directory operations DirectoryGate
- The UI for the application includes all the forms and UI of the application DirectoryGateDO
- static
class for handling the database layer - using Microsoft patterns & practices for best practice approaches HandleError
- static
class handles all the error messages in the application OutputToExcel
- for outputting the results to Excel OutputToHTML
- for outputting the results to HTML
ActiveDirectoryDO
CreateDirectoryEntry
- Returns the DirectoryEntry
by given Domain.
It is used in all update/query/delete Active directory methods.
public static DirectoryEntry CreateDirectoryEntry(string domainADPath)
{
DirectoryEntry LDAPConnection =
new DirectoryEntry(domainADPath);
string[] DomainSplit = domainADPath.Split('.');
LDAPConnection.Path = "LDAP://";
foreach (string Part in DomainSplit)
{
LDAPConnection.Path += "DC=" + Part + ",";
}
int LastCommaInd = LDAPConnection.Path.LastIndexOf(',');
LDAPConnection.Path = LDAPConnection.Path.Remove(LastCommaInd);
LDAPConnection.AuthenticationType = AuthenticationTypes.Secure;
return LDAPConnection;
}
Example for Active directory query method is as follows:
public static void SearchObjectsInActiveDirectory(string domainADPath,
string searchString, ref List<string> deletionObjList)
{
using(DirectoryEntry LDAPConnection = CreateDirectoryEntry(domainADPath)){
using(DirectorySearcher SearchObj =
new DirectorySearcher(LDAPConnection)){
SearchObj.Filter = searchString;
SearchResultCollection Result = SearchObj.FindAll();
foreach (SearchResult SR in Result)
{
ResultPropertyCollection Fields = SR.Properties;
foreach (Object myCollection in Fields
["samAccountName"])
{
deletionObjList.Add
(myCollection.ToString());
}
}
}
}
}
DirectoryGateDO (Using Microsoft Patterns & Practices)
Example for SQL StoredProcedure used for retrieving all the Domains within the database:
public static SqlDataReader GetDomainsFromDB()
{
SqlDatabase db = new SqlDatabase(m_CStr);
DbCommand SComm = db.GetStoredProcCommand("spGetDomainsList");
SqlDataReader SDR = (SqlDataReader)db.ExecuteReader(SComm);
return SDR;
}
Points of Interest
Please come with suggestions and ideas of how to improve the application.
History
- Alpha version of the project