IADsCollection::get__NewEnum method

The IADsCollection::get__NewEnum method gets a dependent enumerator object that implements IEnumVARIANT for this ADSI collection object. Be aware that there are two underscore characters in the function name (get__NewEnum).


HRESULT get__NewEnum(
  IUnknown **ppEnumerator



Pointer to a pointer to the IUnknown interface on the enumerator object for this collection.

Return Value

This method supports the standard return values including S_OK, E_FAIL, or E_NOTIMPL. For more information and other return values, see ADSI Error Codes.


When a server supports paged search and the client has specified the page limit greater than the maximum search results allowed on the server, the IADsCollection::get__NewEnum method returns errors in the following ways:

  • If the server returns an error with no results, the function returns the error only.
  • If the server returns partial results with or without an error, for example, the maximum search results allowed on the server, the function returns the partial results from the server to the user.
  • If the server returns all results with or without an error, for example, maximum search results on each page and all results through multiple pages, the function returns all the results from the server to the user.


The For EachInNext statement in the following Visual Basic code example invokes get__NewEnum method implicitly.

Dim fso As IADsFileServiceOperations 
On Error GoTo Cleanup

Set fso = GetObject("WinNT://myComputer/Fabrikam01")

Dim coll As IADsCollection Set coll = fso.Sessions

' The following statement invokes IADsCollection::get__NewEnum. For Each session In coll MsgBox "Session name: " & session.Name Next session

Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred... " & Err.Number) End If Set fso = Nothing

The following C++ code example shows how IADsCollection::get__NewEnum is used to enumerate active file service sessions.
HRESULT EnumCollection(IADsCollection *);

HRESULT GetACollectionOfSessions() { LPWSTR adspath = L"WinNT://myComputer/LanmanServer"; HRESULT hr = S_OK; IADsCollection *pColl = NULL;

// Bind to file service operations.
IADsFileServiceOperations *pFso = NULL;
hr = ADsGetObject(adspath,
if(FAILED(hr)) {goto Cleanup;}

// Get the pointer to the collection.
hr = pFso-&gt;Sessions(&amp;pColl);
if(FAILED(hr)) {goto Cleanup;}

hr = EnumCollection(pColl);

Cleanup: if(pColl) pColl->Release(); if(pFso) pFso->Release();

return hr;


HRESULT EnumCollection(IADsCollection *pColl) { IUnknown *pUnk=NULL; HRESULT hr = S_OK; // Get the Enumerator object on the collection object. hr = pColl->get__NewEnum(&pUnk); if(FAILED(hr)) {goto Cleanup;}

IEnumVARIANT *pEnum;
hr = pUnk-&gt;QueryInterface(IID_IEnumVARIANT,(void**)&amp;pEnum);
if(FAILED(hr)) {goto Cleanup;}

// Enumerate the collection.
BSTR bstr = NULL;
IADs *pADs = NULL;
ULONG lFetch;
IDispatch *pDisp = NULL;

hr = pEnum-&gt;Next(1, &amp;var, &amp;lFetch);
while(hr == S_OK)
    if (lFetch == 1)    
         pDisp = V_DISPATCH(&amp;var);
         pDisp-&gt;QueryInterface(IID_IADs, (void**)&amp;pADs);
         printf("Session name: %S\n",bstr);
    pDisp = NULL;
    hr = pEnum-&gt;Next(1, &amp;var, &amp;lFetch);

Cleanup: if(pDisp) pDisp->Release(); if(pUnk) pUnk->Release(); if(pColl) pColl->Release(); if(pEnum) pEnum->Release(); return hr; }


Windows version Windows Vista Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See Also

ADSI Error Codes