IADsContainer::Delete method
Applies to: desktop apps only
The IADsContainer::Delete method deletes a specified directory object from this container.
Syntax
HRESULT Delete( [in] BSTR bstrClass, [in] BSTR bstrRelativeName );
Parameters
- bstrClass [in]
-
The schema class object to delete. The name is that returned from the IADs::get_Class method. Also, NULL is a valid option for this parameter. Providing NULL for this parameter is the only way to deal with defunct schema classes. If an instance was created before the class became defunct, the only way to delete the instance of the defunct class is to call IADsContainer::Delete and provide NULL for this parameter.
- bstrRelativeName [in]
-
Name of the object as it is known in the underlying directory and identical to the name retrieved with the IADs::get_Name method.
Return value
This method supports the standard return values, including S_OK for a successful operation. For more information about error codes, see ADSI Error Codes.
Remarks
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.
Examples
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();
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
DLL |
|
|
IID |
IID_IADsContainer is defined as 001677D0-FD16-11CE-ABC4-02608C9E7553 |
See also
- ADSI Error Codes
- IADs::Get
- IADs::GetInfo
- IADs::get_Class
- IADs::get_Name
- IADs::Put
- IADs::SetInfo
- IADsContainer
- IADsContainer::Create
- IADsDeleteOps::DeleteObject
Send comments about this topic to Microsoft
Build date: 2/3/2012