Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code example uses ranging to retrieve the members of a group using the IDirectoryObject interface.
//***************************************************************************
//
// EnumGroupWithIDirectoryObject()
//
//***************************************************************************
HRESULT EnumGroupWithIDirectoryObject(LPCWSTR pwszGroupDN,
LPCWSTR pwszUsername,
LPCWSTR pwszPassword)
{
if(NULL == pwszGroupDN)
{
return E_POINTER;
}
HRESULT hr;
IDirectoryObject *pdo;
hr = ADsOpenObject( pwszGroupDN,
pwszUsername,
pwszPassword,
ADS_SECURE_AUTHENTICATION,
IID_IDirectoryObject,
(void**)&pdo);
if(SUCCEEDED(hr))
{
PADS_ATTR_INFO pAttrInfo;
const DWORD dwStep = 1000;
DWORD dwLowRange;
DWORD dwHighRange;
DWORD dwRetrieved;
WCHAR wszAttr[MAX_PATH];
LPWSTR rgAttrs[1];
rgAttrs[0] = wszAttr;
dwLowRange = 0;
dwHighRange = dwLowRange + (dwStep - 1);
do
{
swprintf_s(wszAttr, L"member;range=%d-%d", dwLowRange, dwHighRange);
hr = pdo->GetObjectAttributes(rgAttrs, 1, &pAttrInfo, &dwRetrieved);
if(SUCCEEDED(hr))
{
DWORD i;
for(i = 0; i < dwRetrieved; i++)
{
DWORD x;
for(x = 0; x < pAttrInfo[i].dwNumValues; x++)
{
wprintf(L"%s\n", pAttrInfo[i].pADsValues[x].CaseIgnoreString);
}
}
FreeADsMem(pAttrInfo);
dwLowRange = dwHighRange + 1;
dwHighRange = dwLowRange + (dwStep - 1);
}
if(0 == dwRetrieved)
{
break;
}
}while(SUCCEEDED(hr));
pdo->Release();
}
return hr;
}