IADsContainer *pContainer;
BSTR bstrContainerPath;
IADsUser *pUser;
BSTR bstrUserName;
//
// Bind to the known object. In this case, we happen to know
// the explicit path, but typically the object will be discovered
// using query or enumeration.
//
ADsGetObject(TEXT("WinNT://MSFT/Users/Jane"),
IID_IADsUser,
(void**)&pUser);
//
// Get the container object path.
//
pUser->get_Parent(&bstrContainerPath);
//
// Get the container object.
//
ADsGetObject(bstrContainerPath,
IID_IADsContainer,
(void**)&pContainer);
//
// Get the user object's name. (This step is unneccesary in
// this example since we already know the name, but is included to
// indicate that we either need to know the name, or have a ptr
// to the object).
//
pUser->get_Name(&bstrUserName);
//
// Release the user object. Note that we are about to delete
// the underlying DS object, so we should not hang on to the user
// component.
//
pUser->Release();
//
// Delete the user.
//
pContainer->Delete(TEXT("user"),bstrUserName);
//
// Cleanup.
//
SysFreeString(bstrContainerPath);
SysFreeString(bstrUserPath);
pContainer->Release();