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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:33:39+00:00 2026-05-20T01:33:39+00:00

First, I have to enumerate all the AD groups of the current user. Getting

  • 0

First, I have to enumerate all the AD groups of the current user. Getting the SID and the name is easy:

foreach(var group in WindowsIdentity.GetCurrent().Groups)
{
   var sid = new SecurityIdentifier(group.Value);
   string name = (group.Translate(typeof(NTAccount)) as NTAccount).Value;
}

Then I need to determine the number of members in each of the groups, and I can’t get that to work. I guess I need a way to get the distinguished name of the groups of the current users. Any idea how to get that?

What I did so far: I tried a WMI query like this, but it returns no results because I would need the fully qualified domain name but NTAccount gives me only the “friendly” domain account (DOMAIN\group):

SELECT PartComponent FROM Win32_GroupUser 
WHERE (GroupComponent = "Win32_Group.Domain='somedomain', Name='somegroup'")

Then I tried LDAP, working around the missing path/Distinguished Name by binding to the SID of the group:

var adGroupEntry = new DirectoryEntry(String.Format("LDAP://<SID={0}>", group.Value));
if (adGroupEntry != null)
{
  IEnumerable members = adGroupEntry.Invoke("Members", null) as IEnumerable;
  if (members != null)
  {
    foreach (object member in members)
    {
      noOfMembers++;
    }
  }
}

It finds the group, the name property returns the correct value, however Members never contains any elements. If I would know the full LDAP path for a group (like when I hard-code it), the code above would actually yield the correct number of users in the group.

What am I missing here? I’m not very familiar with Active Directory or WMI.

Restrictions:

  • I can’t hard-code any domain names or LDAP paths.
  • I’m limited to .NET 2.0, so I can’t use System.DirectoryServices.AccountManagement.
  • 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-20T01:33:40+00:00Added an answer on May 20, 2026 at 1:33 am

    I can repro your problem in my environment. It sounds like a bug in ADSI to me.

    The returned COM object doesn’t work if you are using serverless binding and SID binding at the same time.

    I could workaround that by not using serverless bindnig. i.e. using this LDAP://*yourdomain.com*/<SID={0}> instead

    I could also workaround that by binding the object again.

    var adGroupEntry = new DirectoryEntry(String.Format("LDAP://<SID={0}>",group.Value));
    string dn = adGroupEntry.Properties["distinguishedName"].Value as string;
    DirectoryEntry de = new DirectoryEntry("LDAP://" + dn);
    if (de != null)
    {
        IEnumerable members = de.Invoke("Members", null) as IEnumerable;
        if (members != null)
        {
            foreach (object member in members) 
            {
                noOfMembers++;     
            }   
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.