Directory Services

IADsDeleteOps Interface

The IADsDeleteOps interface is used in supervisory and maintenance routines for the underlying directory store. It can delete 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 operation.

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

[C++]
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(
			 CComBSTR("LDAP://primedom/CN=Eng,CN=Users,DC=Fabrikam,DC=Com"),
			 CComBSTR("Administrator"),
			 CComBSTR("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 group.
			pOps->DeleteObject(0);
			pOps->Release();
	}
}
}
[C++]
HRESULT hr;
IADsOpenDSObject *pDSO;
BSTR bstrAdministrator = NULL;
BSTR bstrPassword = NULL;

// Insert code to securely retrieve the username and password
// or leave as NULL to use the default security context of the 
// calling application.

 
// 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(
			 CComBSTR("LDAP://primedom/CN=Eng,CN=Users,DC=Fabrikam,DC=Com"),
			 bstrAdministrator,
			 bstrPassword,
			 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 group.
			pOps->DeleteObject(0);
			pOps->Release();
	}
}
}