Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer::Delete

The IADsContainer::Delete method deletes a specified directory object from this container.

HRESULT IADsContainer::Delete(
  BSTR bstrClass,        
  BSTR bstrRelativeName  
);

Parameters

bstrClass
[in] Name of the schema class object to be deleted. The name is that returned from the IADs::get_Schema method.
bstrRelativeName
[in] Name of the object as it is known in the underlying directory and identical to the one retrieved through the IADs::get_Name method.

Return Values

This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.

Remarks

To object to be deleted must be a leaf object or a childless sub-container. To delete a container together with all its children (that is, a subtree), use IADsDeleteOps::DeleteObject.

The specified object will not be permanently removed from the underlying directory store unless the IADs::SetInfo method is called on the container object.

When using the IADsContainer::Delete method to delete an object in C/C++ applications, you should release the interface pointers to that object as well. This is because the method removes the object from the underlying directory immediately, but leave intact any interface pointers held by the application, that is, in memory, for the deleted object. If they are not released, confusing situations might arise in which you may call IADs::Get and IADs::Put on the deleted object without error, but will get an error when you call IADs::SetInfo or IADs::GetInfo on the deleted object.

Example Code [Visual Basic]

The following Visual Basic code snippet deletes a user object from the container in Active Directory.

Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
cont.Delete "user", "CN=JSmith"

The following code snippet deletes the user object from the container under WinNT provider.

Set cont = GetObject("WinNT://Fabrikam")
cont.Delete "user", "jsmith"

Example Code [C++]

The following C++ code snippet shows how to delete a user using IADsContainer::Delete.

HRESULT hr;
IADsContainer *pCont=NULL;
 
CoInitialize(NULL);
 
hr = ADsGetObject(L"WinNT://myMachine", 
                  IID_IADsContainer, 
                  (void**) &pCont);
if ( !SUCCEEDED(hr) )
{
     return hr;
}
 
hr = pCont->Delete(L"user", L"JaneSmith");
pCont->Release();

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

IADsContainer, IADsContainer::Create