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 6192975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:02:17+00:00 2026-05-24T03:02:17+00:00

Where can I find an example that does the following? Pulls a user from

  • 0

Where can I find an example that does the following?

  1. Pulls a user from Active Directory.
  2. Gets the groups the user is a member of.
  3. Gets a list of permissions assigned to each group.

This seems like a simple task but I can’t find a solution.

The overall goal is to assign custom permissions and use them to control rights within an application.

  • 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-24T03:02:18+00:00Added an answer on May 24, 2026 at 3:02 am

    If you’re on .NET 3.5 and up, 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....     
    }
    
    // find the group in question
    GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");
    
    // if found....
    if (group != null)
    {
       // iterate over members
       foreach (Principal p in group.GetMembers())
       {
          Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
          // do whatever you need to do to those members
       }
    }
    

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

    The last point: permissions. Those aren’t stored in Active Directory – and therefore, you can’t retrieve those from any AD code.

    Permissions are stored on the individual file system items, e.g. files and/or directories – or other objects (like registry keys, etc.). When you have an AD group or user account, you can read it’s SID (Security Identifier) property – that SID will show up in ACL’s (Access Control Lists) all over Windows – but from the user or group, there’s no mechanism to get all permissions it might have anywhere in the machine/server.

    Permissions for files and directories can e.g. be retrieved using the .GetAccessControl() method on the FileInfo and DirectoryInfo classes:

    FileInfo info = new FileInfo(@"D:\test.txt");
    FileSecurity fs = info.GetAccessControl();
    
    DirectoryInfo dir = new DirectoryInfo(@"D:\test\");
    DirectorySecurity ds = dir.GetAccessControl();
    

    Deciphering and making sense of those is a whole different story altogether!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I find a RSA encrypt example that does not use NoPadding? --update
I find it annoying that I can't clear a list. In this example: a
How can I find elements that has at least one attribute? Example: <tr>...</tr> <tr
Does anyone know where I can find an example of how to determine if
Does anyone know where I can find an example or a tutorial of building
I can't find a reason why the following does not work. If I have
Does anyone know where I can find some example code for implementing ajax tabs
I wrote the following script so that an end-user can create a word document
I've looked around but I can't seem to find an API call that does
I'm working in Delphi 2007. Net, where I can find an example of using

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.