Directory Services |
The IADsContainer::Delete method deletes a specified directory object from this container.
HRESULT Delete( BSTR bstrClass, BSTR bstrRelativeName );
This method supports the standard return values, including S_OK for a successful operation. For more information about error codes, see ADSI Error Codes.
The object to be deleted must be a leaf object or a childless subcontainer. To delete a container and its children, that is, a subtree, use IADsDeleteOps::DeleteObject.
The specified object is immediately removed after calling IADsContainer::Delete and calling IADs::SetInfo on the container object is unnecessary.
When using the IADsContainer::Delete method to delete an object in C/C++ applications, 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, in memory, by the application, for the deleted object. If not released, confusion can occur in that you may call IADs::Get and IADs::Put on the deleted object without error, but will receive an error when you call IADs::SetInfo or IADs::GetInfo on the deleted object.
The following code example deletes a user object from the container in Active Directory.
Dim cont as IADsContainer On Error GoTo Cleanup Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com") cont.Delete "user", "CN=JeffSmith" Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set cont = Nothing
The following code example deletes a user object from the container under WinNT provider.
Dim cont as IADsContainer On Error GoTo Cleanup Set cont = GetObject("WinNT://Fabrikam") cont.Delete "user", "jeffsmith" Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set cont = Nothing
The following code example deletes a user using IADsContainer::Delete.
HRESULT hr = S_OK; IADsContainer *pCont=NULL; CoInitialize(NULL); hr = ADsGetObject(L"WinNT://myMachine", IID_IADsContainer, (void**) &pCont); if ( !SUCCEEDED(hr) ) { return hr; } hr = pCont->Delete(CComBSTR("user"), CComBSTR("JeffSmith")); pCont->Release();
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.
ADSI Error Codes, IADs::Get, IADs::GetInfo, IADs::get_Class, IADs::get_Name, IADs::Put, IADs::SetInfo, IADsContainer, IADsContainer::Create, IADsDeleteOps::DeleteObject