Platform SDK: Active Directory, ADSI, and Directory Services

IADsCollection::GetObject

The IADsCollection::GetObject method retrieves an item of the collection.

HRESULT IADsCollection::GetObject(
  BSTR bstrName,
  VARIANT pvarItem
);

Parameters

bstrName
[in] Name of the item. This is the same name passed to IADsCollection::Add when the item is added to the collection.
pvarItem
[in] Current value of the item. For an object, this corresponds to the IDispatch interface pointer on the object.

Return Values

This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.

Remarks

If you know the name of a session in the Sessions collection, you can call the IADsCollection::GetObject method explicitly to retrieve the session object.

Example Code [Visual Basic]

The following Visual Basic code snippet shows how to retrieve a named session object (mySession) from a collection of active file service sessions.

Dim fso as IADsFileServiceOperations 
Dim ses as IADsSession
Dim coll as IADsCollection

Set fso = GetObject("WinNT://myComputer/LanmanServer") 
 Set coll = fso.Sessions
 
' The following statement invokes IADsCollection::GetObject.
Set ses = coll.GetObject(mySessionName)

Example Code [C++]

The following C++/C code snippet shows how to retrive a named session object (mySession) from a collection of active file service sessions.

HRESULT GetASessionObjectFromCollection(LPWSTR mySession)
{
    LPWSTR adspath = L"WinNT://myComputer/LanmanServer";
    IUnknown *pUnk=NULL;
    HRESULT hr;
    IADsCollection *pColl;
    IADsFileServiceOperations *pFso;

    hr = ADsGetObject(adspath, 
                      IID_IADsFileServiceOperations,
                      (void**)&pFso);
    if(FAILED(hr)) return hr;

    hr = pFso->Sessions(&pColl);
    if(FAILED(hr)) return hr;
    pFso->Release();

    VARIANT varObj;
    VariantInit(&varObj);
    hr = pColl->GetObject(mySession &varObj);
    IADs *pADsObj;
    V_DISPATCH(&varObj)->QueryInterface(IID_IADs,(void**)&pADsObj);
    BSTR bstrObj;
    hr = pADsObj->get_Class(&bstrObj);
    printf("Class of the object obtained from GetObject: %S\n",
             bstrObj);
    SysFreeString(bstrObj);

    VariantClear(&varObj);
    pADsObj->Release();
    pColl->Release();

    return S_OK;
}

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

IEnumVARIANT, IADsCollection::Add, ADSI Error Codes