List all AD groups in a checkedListBox

Asked

Viewed 117 times

0

I would like to know how to list all AD groups with C# Forms, and list in a checkedListBox, in several searches I did, I only found how to list the groups of a specific user.

Note: I put the data of my AD user to do the search.

  • 1

    What have you tried?

  • Show how you are doing the query.

  • I posted the code that I came closest to getting.

1 answer

0

if (userName == "" || password == "")
        {
            return false;
        }

        try
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, userName, password);
            DirectorySearcher mySearcher = new DirectorySearcher(entry);
            mySearcher.Filter = "(&(objectClass=user)(|(cn=" + userName + ")(sAMAccountName=" + userName + ")))";
            SearchResult result = mySearcher.FindOne();

            foreach (string GroupPath in result.Properties["memberOf"])
            {
                checkedListBox1.Items.Add(GroupPath);
                if (GroupPath.Contains(group))
                {

                    return true;
                }
            }
        }
        catch (DirectoryServicesCOMException)
        {
        }
        return false;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.