Click here to Skip to main content
13,552,926 members
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 23 Apr 2009
Licenced CPOL

Active Directory Tool

, 25 Apr 2009
Rate this:
Please Sign up or sign in to vote.
Active directory tool - helps manage active directory oparations (query, update and delete) with easy to use GUI


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


It is part of college final project.


  • 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= 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:

  1. ActiveDirectoryDO - static class handles all the active directory operations
  2. DirectoryGate - The UI for the application includes all the forms and UI of the application
  3. DirectoryGateDO - static class for handling the database layer - using Microsoft patterns & practices for best practice approaches
  4. HandleError - static class handles all the error messages in the application
  5. OutputToExcel - for outputting the results to Excel
  6. OutputToHTML - for outputting the results to HTML


CreateDirectoryEntry - Returns the DirectoryEntry by given Domain.

It is used in all update/query/delete Active directory methods.

public static DirectoryEntry CreateDirectoryEntry(string domainADPath)
            // create and return new LDAP connection with desired settings
            DirectoryEntry LDAPConnection = 
			new DirectoryEntry(domainADPath); //

            string[] DomainSplit = domainADPath.Split('.');

            //LDAPConnection.Path = "LDAP://DC=litwareinc,DC=com";
            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)
            // create LDAP connection object
            using(DirectoryEntry LDAPConnection = CreateDirectoryEntry(domainADPath)){

            	using(DirectorySearcher SearchObj = 
				new DirectorySearcher(LDAPConnection)){

            		// Groups + Users Search
            		SearchObj.Filter = searchString;

            		SearchResultCollection Result = SearchObj.FindAll();

            		foreach (SearchResult SR in Result)
                			ResultPropertyCollection Fields = SR.Properties;

                			foreach (Object myCollection in Fields

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);
        // 1.  create a command object identifying
       //     the stored procedure
        DbCommand SComm = db.GetStoredProcCommand("spGetDomainsList");
        // execute the command
        SqlDataReader SDR = (SqlDataReader)db.ExecuteReader(SComm);
        return SDR;

Points of Interest

Please come with suggestions and ideas of how to improve the application.


  • Alpha version of the project


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Israel Israel
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMemory Leak Pin
dlesko24-Apr-09 13:32
memberdlesko24-Apr-09 13:32 
GeneralRe: Memory Leak Pin
Yair Rozenberg24-Apr-09 22:03
memberYair Rozenberg24-Apr-09 22:03 
GeneralRe: Memory Leak Pin
Yair Rozenberg25-Apr-09 8:26
memberYair Rozenberg25-Apr-09 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 25 Apr 2009
Article Copyright 2009 by yairrose
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid