Platform SDK: Active Directory, ADSI, and Directory Services

IADsDeleteOps Interface

The IADsDeleteOps interface is used primarily in supervisory and maintenance routines for the underlying directory store. It is capable of deleting both leaf objects and entire subtrees in a single operation.

If this interface is not supported, deleting an object from Active Directory requires that each contained object be recursively enumerated and deleted individually. With this interface, any container object — along with all of its contained objects and subobjects — can be deleted with a single call.

This example deletes the entire "Eng" (Engineering) group from the Users list on an LDAP server.

HRESULT hr;
IADsOpenDSObject *pDSO;
 
// Bind to the LDAP provider.
hr = ADsGetObject(L"LDAP:", IID_IADsOpenDSObject, (void **) &pDSO);
if (SUCCEEDED(hr))
{
    // Get the dispatch interface pointer using Administrator credentials.
    IDispatch *pDisp;
    hr = pDSO->OpenDSObject(
             L"LDAP://primedom/CN=Eng,CN=Users,DC=Microsoft,DC=Com",
             L"Administrator",
             L"passwordgoeshere",
             ADS_SECURE_AUTHENTICATION, &pDisp);
    pDSO->Release();
 
    if (SUCCEEDED(hr))
    {
        // Get the DeleteOps interface pointer.
        IADsDeleteOps *pOps;
        hr = pDisp->QueryInterface(IID_IADsDeleteOps, (void**) &pOps);
        pDisp->Release();
 
        if (SUCCEEDED(hr))
        {
            // Delete the whole group.
            pOps->DeleteObject(0);
            pOps->Release();
        }
    }
}