Platform SDK: Active Directory, ADSI, and Directory Services

IADsCollection::Remove

The IADsCollection::Remove method removes the named item from this ADSI collection object.

HRESULT IADsCollection::Remove(
  BSTR bstrItemToBeRemoved
);

Parameters

bstrItemToBeRemoved
[in] Name of the item as it was specified by IADsCollection::Add.

Return Values

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

Remarks

Collections for a directory service can also consist of a set of immutable objects.

Collections that do not support direct removal of items are required to return E_NOTIMPL.

Example Code [Visual Basic]

The following Visual Basic code snippet shows how to remove 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::Remove.
coll.Remove mySessionName

Example Code [C++]

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

HRESULT RemoveASessionObjectFromCollection()
{
    LPWSTR adspath = L"WinNT://myComputer/LanmanServer";
    LPWSTR mySession = L"MySession";
    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();

    hr = pColl->Remove(mySession);
    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

IADsCollection::Add, ADSI Error Codes