How would I go about querying what active directory group the currently logged in user belongs to? Below I add the example code which is similar to what I want. In that code they use "WinNT" method to work on it. But I want to use Ldap format like this -> hr = ADsOpenObject(L"LDAP://10.20.214.74/OU=Vimal,DC=test,DC=local". Can anyone please help me to find the solution? Thanks in Advance.
IADsGroup *pGroup = NULL;
HRESULT hr = S_OK;
LPWSTR adsPath = L"WinNT://Fabrikam/Administrators";
BSTR bstr = NULL;
hr = ADsGetObject(adsPath, IID_IADsGroup, (void**)&pGroup);
if(FAILED(hr))
{
goto Cleanup;
}
hr = pGroup->get_Description(&bstr);
if(FAILED(hr))
{
goto Cleanup;
}
printf("Description: %S\n",bstr);
SysFreeString(bstr);
VARIANT_BOOL inG=false;
hr = pGroup->IsMember(CComBSTR("WinNT://Microsoft/SecUser"), &inG);
if (inG )
{
printf("already in the group.\n");
}
else
{
hr = pGroup->Add(CComBSTR("WinNT://Microsoft/SecUser"));
if(FAILED(hr))
{
goto Cleanup;
}
printf("user added.\n");
}
Cleanup:
if(pGroup)
{
pGroup->Release();
}
if(bstr)
{
SysFreeString(bstr);
}
return hr;