Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsContainer::Delete method deletes a specified directory object from this container.
HRESULT IADsContainer::Delete( BSTR bstrClass, BSTR bstrRelativeName );
This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.
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.
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"
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();
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.