IADsGroup *pGroup;
IADsMembers *pMembers;
IEnumVARIANT *pEnum;
IADs *pMember;
BSTR bstrMemberName;
//
// Bind to a known group object.
//
ADsGetObject(TEXT("WinNT://MSFT/Groups/Administrators"),
IID_IADsGroup,
(void**)&pGroup);
//
// Get the Members collection.
//
pGroup->Members(&pMembers);
//
// Get an enumerator. ADsBuildEnumerator is a helper
// function supplied by ADSI. See Appendix B for more
// details.
//
ADsBuildEnumerator((IADsContainer *)pMembers,
&pEnum);
//
// Enumerate through all the children of the container.
// ADsEnumerateNext is a helper function supplied by ADSI.
// See Appendix B for more details.
//
do {
hr = ADsEnumerateNext(pEnum,
1,
(void**)&pMember,
NULL);
if (SUCCEEDED(hr))
{
pMember->get_Name(&bstrMemberName);
printf("%s\n", bstrMemberName);
SysFreeString(bstrMemberName);
pMember->Release();
} // if
} while (SUCCEEDED(hr)); // do
//
// Cleanup.
//
pEnum->Release();
pMembers->Release();
pGroup->Release();