0
我正努力爲給定用戶(domain1/user1)獲取所有組... 下面的C程序(在domain1中的機器上運行)工作正常,但它不顯示來自其他域的組.. User1也是domain2的一部分,但下面的代碼不顯示該信息.. 我突然想出其他選項,但沒有運氣。 。 難道你們提供什麼建議?爲給定用戶提取所有組(全局,通用,域本地)
void printGroups()
{
IADsUser *pUser;
IADsMembers *pGroups;
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) return -1;
IID iid = IID_IADsUser;
hr = ADsGetObject(L"WinNT://domain1/user1", &iid, (void**)&pUser);
if (FAILED(hr)) {
printf("blad");
return -1;
}
pUser->lpVtbl->Groups(pUser, &pGroups);
//pUser->Groups(&pGroups);
pUser->lpVtbl->Release(pUser);
//pUser->Release();
if (FAILED(hr)) return -1;
IUnknown *pUnk;
hr = pGroups->lpVtbl->get__NewEnum(pGroups, &pUnk);
if (FAILED(hr)) return -1;
pGroups->lpVtbl->Release(pGroups);
IEnumVARIANT *pEnum;
iid = IID_IEnumVARIANT;
hr = pUnk->lpVtbl->QueryInterface(pUnk, &iid, (void**)&pEnum);
if (FAILED(hr)) return -1;
pUnk->lpVtbl->Release(pUnk);
// Enumerate.
BSTR bstr;
VARIANT var;
IADs *pADs;
ULONG lFetch;
IDispatch *pDisp;
VariantInit(&var);
hr = pEnum->lpVtbl->Next(pEnum, 1, &var, &lFetch);
while (hr == S_OK)
{
if (lFetch == 1)
{
pDisp = V_DISPATCH(&var);
iid = IID_IADs;
pDisp->lpVtbl->QueryInterface(pDisp, &iid, (void**)&pADs);
pADs->lpVtbl->get_Name(pADs, &bstr);
//printf("Group Name: %S\n", bstr);
pADs->lpVtbl->get_ADsPath(pADs, &bstr);
printf("Group ADPath: %S\n", bstr);
SysFreeString(bstr);
pADs->lpVtbl->Release(pADs);
}
VariantClear(&var);
pDisp = NULL;
hr = pEnum->lpVtbl->Next(pEnum, 1, &var, &lFetch);
};
hr = pEnum->lpVtbl->Release(pEnum);
return 0;
}