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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:31:01+00:00 2026-06-12T03:31:01+00:00

I am writing a standalone application that needs to, given a AD account name,

  • 0

I am writing a standalone application that needs to, given a AD account name, figure out if the user is a member of a particular group. I am writing the application in .NET (C#). The structure in AD looks like this:

  • Organization
    • Team 1
      • David (user)
  • Groups
    • Application A
      • Team 1 (group from above)

Just listing the memberships for David will not show that he is a member of the Application A group.

I understand from Microsoft’s documentation that (using the principals) I could simply use the IsInRole call, but I cannot find any case that doesn’t require David to be logged on to the machine or running the application performing the check. I think my limited understanding of the security model also comes into play here.

Could someone please point me in the right direction? What I am looking for is hints on how to solve above (references, tips, snippets) in C#, without depending on David having to run any application.

Let me know if anything can be clarified.

  • 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-06-12T03:31:02+00:00Added an answer on June 12, 2026 at 3:31 am

    Add a reference to DirectoryServices.AccountManagement

    Then add a using statement:

    using System.DirectoryServices.AccountManagement;
    

    Then in your main procedure (or somewhere else, where required, call the Procedure IsMember:

    string userName = "David";
    string GroupName = "Team 1";
    bool test = IsMember(userName, GroupName);
    

        public static bool IsMember(string UserName, string GroupName)
        {
            try
            {
                UserPrincipal user = UserPrincipal.FindByIdentity(
                    new PrincipalContext(ContextType.Domain),
                    UserName);
    
                foreach (Principal result in user.GetAuthorizationGroups())
                {
                    if (string.Compare(result.Name, GroupName, true) == 0)
                        return true;
                }
                return false;
            }
            catch (Exception E)
            { 
                throw E; 
            }
        }
    

    If David is in Team 1, the procedure will return true, otherwise false.

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

Sidebar

Related Questions

I am writing a standalone application in Java that needs to be able to
I'm writing a standalone application in VB.NET using Visual Studio 2005. I want to
I'm writing a Java application that needs a lot of static data that is
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
I'm writing a standalone application and I thought using Entity Framework to store my
I'm writing an application that that I'm going to provide as a service and
I am writing an android application that requires a large amount of bandwith to
I am writing a XUL application following the default structure for standalone XUL apps
I am writing an MDI application in C# that contains two child forms which
I'm writing a small application for Windows 7 that will track focused programs and

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.