IADsUser::Groups method
Applies to: desktop apps only
The IADsUser::Groups method obtains a collection of the ADSI group objects to which this user belongs. The method returns an IADsMembers interface pointer through which you can enumerate all the groups in the collection.
Syntax
HRESULT Groups( [out] IADsMembers **ppGroups );
Parameters
- ppGroups [out]
-
Pointer to a pointer to the IADsMembers interface on a members object that can be enumerated using IEnumVARIANT to determine the groups to which this end-user belongs.
Return value
This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.
Examples
The following code example examines the group membership of a user.
Dim usr As IADsUser On Error GoTo Cleanup Set usr = GetObject("WinNT://Fabrikam/JeffSmith,user") For Each grp In usr.Groups Debug.Print grp.Name & " (" & grp.Class & ")" Next Cleanup: If(Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set usr = Nothing
The following code example examines the group memberships of a user.
HRESULT CheckUserGroups(IADsUser *pUser)
{
IADsMembers *pGroups;
HRESULT hr = S_OK;
hr = pUser->Groups(&pGroups);
pUser->Release();
if (FAILED(hr)) return hr;
IUnknown *pUnk;
hr = pGroups->get__NewEnum(&pUnk);
if (FAILED(hr)) return hr;
pGroups->Release();
IEnumVARIANT *pEnum;
hr = pUnk->QueryInterface(IID_IEnumVARIANT,(void**)&pEnum);
if (FAILED(hr)) return hr;
pUnk->Release();
// Enumerate.
BSTR bstr;
VARIANT var;
IADs *pADs;
ULONG lFetch;
IDispatch *pDisp;
VariantInit(&var);
hr = pEnum->Next(1, &var, &lFetch);
while(hr == S_OK)
{
if (lFetch == 1)
{
pDisp = V_DISPATCH(&var);
pDisp->QueryInterface(IID_IADs, (void**)&pADs);
pADs->get_Name(&bstr);
printf("Group belonged: %S\n",bstr);
SysFreeString(bstr);
pADs->Release();
}
VariantClear(&var);
pDisp=NULL;
hr = pEnum->Next(1, &var, &lFetch);
};
hr = pEnum->Release();
return S_OK;
}
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
DLL |
|
|
IID |
IID_IADsUser is defined as 3E37E320-17E2-11CF-ABC4-02608C9E7553 |
See also
Send comments about this topic to Microsoft
Build date: 2/3/2012