Directory Services


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

HRESULT Remove( 
  BSTR bstrItemToBeRemoved


[in] The null-terminated Unicode string that specifies the name of the item as it was specified by IADsCollection::Add.

Return Values

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.

Example Code [Visual Basic]

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

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

Example Code [C++]

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";
	IADsCollection *pColl = NULL;
	IADsFileServiceOperations *pFso = NULL;

	hr = ADsGetObject(adspath, 
	if(FAILED(hr)) {goto Cleanup;}

	hr = pFso->Sessions(&pColl);
	if(FAILED(hr)) {goto Cleanup;}

	hr = pColl->Remove(CComBSTR("MySession"));

	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.

See Also

IADsCollection::Add, ADSI Error Codes