sijith

sijith

  • NA
  • 1
  • 0

Listing users in active directory from local machine

Oct 8 2009 8:44 AM
Hi. Here i want to list all active users in active directory by sitting in local machine. Is it possible to do. Please help in programming side. My code is here ActiveDir::ActiveDir(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); HRESULT hr; IADsContainer *pCont = NULL; CoInitialize(NULL); hr = ADsGetObject(L"WinNT://avrstudio.com", IID_IADsContainer, (void**) &pCont ); // WinNT:// if ( !SUCCEEDED(hr) ) { printf("ADsGetObject Failed"); return; } else printf("cvdsvdv"); _variant_t var; IEnumVARIANTPtr pEnum; ADsBuildEnumerator (pCont,&pEnum); int cnt=0; ULONG ulFetched = 0L; _variant_t vChild; hr= ADsEnumerateNext(pEnum, 1, &vChild, &ulFetched) ; printf("@@@ %d ulFetched",ulFetched); while((SUCCEEDED(ADsEnumerateNext(pEnum, 1, &vChild, &ulFetched)) /*&& (ulFetched>0)*/)) { IADsUser* pADs; hr = V_DISPATCH(&vChild)->QueryInterface(IID_IADsUser, (void**)&pADs); /* Here i am getting error.... Getting vChild as empty. what i have to do.. Not getting any idea.. Please guide me */ if ( !SUCCEEDED(hr) )/* This getting failed, hr returning false*/ { printf("\n V_DISPATCH Failed"); } if(hr!=S_OK) break; BSTR bstrName; pADs->get_Name(&bstrName); SysFreeString(bstrName); printf("%s\n",bstrName); pADs->Release(); pADs = NULL; } // Cleanup. if ( pCont ) { pCont->Release(); } CoUninitialize(); } Please help

Answers (1)