Platform SDK: Active Directory, ADSI, and Directory Services |
Unlike Windows NT® 4.0 domains, Windows® 2000 groups can be placed in any container or organizational unit in a domain as well as the root of the domain. This means that groups can be in numerous locations in the directory hierarchy. Therefore, you have two choices for enumerating groups:
Explicitly bind to the container object containing the groups you are interested in enumerating, set a filter containing "groups" as the class using the IADsContainer::put_Filter property method, and use the IADsContainer::get__NewEnum method to enumerate the group objects.
This technique is useful if you want to enumerate groups that are directly contained in a container or OU object. If the container contains other containers that can potentially contain other groups, you need to bind to those containers and recursively enumerate the groups on those containers. If you do not need to manipulate the group objects and only need to read specific properties, you should use the deep search described in option 2.
First, bind to the container object where you want to begin the search. For example, if you wanted to find all groups in a domain, you would bind to root of the domain; if you wanted to find all groups in the forest, you would bind to global catalog and search from the root of the GC.
Then use IDirectorySearch to query using a search filter containing (objectCategory=group) and search preference of ADS_SCOPE_SUBTREE.
Note You can perform a search with a search preference of ADS_SCOPE_ONELEVEL to limit the search to the direct contents of the container object that you bound to.
IDirectorySearch retrieves only the values of specific properties from groups. If you only want to retrieve values, you should use IDirectorySearch. If you want to manipulate the group objects returned from a search (that is, you want to use IADs or IADsGroup methods), you must explicitly bind to them (to do this, specify distinguishedName as one of the properties to return from the search and use the returned distinguished names to bind to each group returned in the search).
Only specific properties are retrieved. You cannot retrieve all attributes without explicitly specifying every possible attribute of the group class.