Active Directory - basics to pull up user info

Posted on 2007-11-20
Last Modified: 2008-02-01
Hello Experts,

I know a bit about programming, but I know basically nothing about active directory.  I've tried looking this up online, but haven't had any success.  Could someone post a snippet of code that would lets say display all users?

Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

DavidTMoore earned 500 total points
ID: 20322886
This might not be exactly what you are looking for, but these are the methods I use to interact with active directory, take a look and maybe they can give you a better understanding of how some of this works.
public static DirectoryEntry GetDirectoryEntry()
        DirectoryEntry de = new DirectoryEntry("LDAP://19dc01", "USERNAME", "PASSWORD");
        return de;
    public bool UserExists(string username)
        DirectoryEntry de = GetDirectoryEntry();
        DirectorySearcher deSearch = new DirectorySearcher();
        deSearch.SearchRoot = de;
        deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";
        SearchResultCollection results = deSearch.FindAll();
        return results.Count > 0;
    public String GetProperty(String userAccount, String propertyName)
        DirectoryEntry entry = GetDirectoryEntry();
        String account = userAccount.Replace(@"DOMAIN\", "");
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "(SAMAccountName=" + account + ")";
            SearchResult result = search.FindOne();
            if (result != null)
                return result.Properties[propertyName][0].ToString();
                return "Unknown User";
        catch (Exception ex)
            string debug = ex.Message;
            return "";

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question