Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7567415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:39:36+00:00 2026-05-30T14:39:36+00:00

I am trying to get the user information for a specific domain which will

  • 0

I am trying to get the user information for a specific domain which will be the input of the program. On the basis of the domain name it should return the list of the users name/ or NT Id and SID of the user. I am new for the ldap programming can any one help me for get this list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:39:37+00:00Added an answer on May 30, 2026 at 2:39 pm

    If you’re on .NET 3.5 and up and talking about Active Directory, then you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

    • Managing Directory Security Principals in the .NET Framework 3.5
    • MSDN docs on System.DirectoryServices.AccountManagement

    Basically, you can define a domain context and easily find users and/or groups in AD:

    // set up domain context
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
    // find a user
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
    
    if(user != null)
    {
       // do something here....     
       var usersSid = user.Sid;
    
       // not sure what you mean by "username" - the "DisplayName" ? The "SAMAccountName"??
       var username = user.DisplayName;
       var userSamAccountName = user.SamAccountName;
    }
    

    The new S.DS.AM makes it really easy to play around with users and groups in AD!

    Update: if you need to loop through all the users of a domain – try this:

    You can use a PrincipalSearcher and a “query-by-example” principal to do your searching:

    // create your domain context
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
    // define a "query-by-example" principal - here, we search for a UserPrincipal 
    UserPrincipal qbeUser = new UserPrincipal(ctx);
    
    // create your principal searcher passing in the QBE principal    
    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
    
    // find all matches
    foreach(var found in srch.FindAll())
    {
        UserPrincipal user = found as UserPrincipal;
    
        if(user != null)
        {
           // do whatever here 
           var usersSid = user.Sid;
    
           // not sure what you mean by "username" - the "DisplayName" ? 
           var username = user.DisplayName;
           var userSamAccountName = user.SamAccountName;
        }
    }
    

    Update #2: if you can’t (or don’t want to) use the S.DS.AM approach – which is the easiest, for Active Directory, by far – then you need to fall back to the System.DirectoryServices classes and methods:

    // define the root of your search
    DirectoryEntry root = new DirectoryEntry("LDAP://dc=YourCompany,dc=com");
    
    // set up DirectorySearcher  
    DirectorySearcher srch = new DirectorySearcher(root);
    srch.Filter = "(objectCategory=Person)";
    srch.SearchScope = SearchScope.Subtree;
    
    // define properties to load
    srch.PropertiesToLoad.Add("objectSid");
    srch.PropertiesToLoad.Add("displayName");
    
    // search the directory
    foreach(SearchResult result in srch.FindAll())
    {
       // grab the data - if present
       if(result.Properties["objectSid"] != null && result.Properties["objectSid"].Count > 1)
       {
           var sid = result.Properties["objectSid"][0];
       }
    
       if(result.Properties["displayName"] != null && result.Properties["displayName"].Count > 0)
       {
           var userName = result.Properties["displayName"][0].ToString();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the contents of User Information List. This list can
i'm trying to get user's public information (name, photo, gender, profile link). as i
I'm trying to get a list of user's friends using fb connect for the
i'm trying to get this program to break down a user defined amount of
I am trying to get FB user's full name using the access_token. I have
I'm trying to query the FourSquare API to obtain user-specific information and venue centric
I'm trying to get all the categories about the specific blogpost but it will
I encountered strange problem - when Im trying to get User information from SalesForce
I have an Activity in which user can update a specific information clicking in
I'm trying to get user GUID from Active Directory. My code: DirectoryEntry entry =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.