Directory Services |
The IADsCollection::Remove method removes the named item from this ADSI collection object.
HRESULT Remove( BSTR bstrItemToBeRemoved );
This method supports the standard return values, including S_OK. For more information and other return values, see ADSI Error Codes.
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.
The following Visual Basic code example 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 Dim mySessionName As String On Error GoTo Cleanup Set fso = GetObject("WinNT://myComputer/FabrikamServer") Set coll = fso.Sessions ' Insert code to set mySessionName to the name of the mySession ' session object. ' The following statement invokes IADsCollection::Remove. coll.Remove mySessionName Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set fso = Nothing Set ses = Nothing Set coll = Nothing
The following C++ code example shows how to remove a named session object (mySession) from a collection of active file service sessions.
HRESULT RemoveASessionObjectFromCollection() { LPWSTR adspath = L"WinNT://myComputer/FabrikamServer"; HRESULT hr = S_OK; IADsCollection *pColl = NULL; IADsFileServiceOperations *pFso = NULL; hr = ADsGetObject(adspath, IID_IADsFileServiceOperations, (void**)&pFso); if(FAILED(hr)) {goto Cleanup;} hr = pFso->Sessions(&pColl); if(FAILED(hr)) {goto Cleanup;} hr = pColl->Remove(CComBSTR("MySession")); Cleanup if(pFso) pFso->Release(); if(pColl) pColl->Release(); return hr; }
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.