4.1.3 Binding to the Default Container

Active Directory defines the concept of a default container to provide a quick way of getting a pointer to a previously identified Active Directory container. This is especially useful when an explicit ADsPath string is not known to the Active Directory client or the client would like to start browsing at a specific, previously set location.

The default container simply contains the ADsPath of a "starting point" in a given DS for a particular user. Users can save the ADsPath of their "favorite starting point" in the default container.

Active Directory defines the DefaultContainer for the namespaces object. The namespaces object is implemented by Active Ds and is always obtained with the ADsPath "ADS://" or "@ADS!//".. Microsoft provides the implementation if the namespaces object.. Note: setting the default container takes effect immediately.

The default container allows a client to obtain an interface pointer on a container component using only the ADsPath string of the namespaces object. As noted above, the ADsPath string of the namespaces object is always known, for Active Directory version 1.1, to be "ADS://" or "@ADS!//".

The following code example demonstrates how to bind to the default container and print its name.

Example 1: Binding to the Default Container (Visual Basic)

Dim NamespacesObj as IADsNamespaces

Dim ReturnedContainer as IADsContainer

Dim ContainedOBject as IADs

'Bind to the Namespaces container.

Set NamespacesObj = GetObject("ADS://")

' Get the default container.

Set ReturnedContainer = GetObject(NamespacesObj.DefaultContainer)

Debug.Print ReturnedContainer.Name

' Use the Default Container as a starting point for other operations

' such as browsing the namespace, etc.

for each ContainedObject in ReturnedContainer

Debug.Print ContainedObject.Name

next ContainedObject

Example 1: Binding to the Default Container (C/C++)

IADs *pNamespacesObj;

IADs *pDefaultContainer;

BSTR bstrDefaultContainerPath;

BSTR bstrName;

//

// Bind to the Namespaces object.

//

ADsGetObject(TEXT("ADS://"),

IID_IADsNamespaces,

(void**)&pNamespacesObj);

//

// Get the default container path and bind to it.

//

pNamespacesObj->get_DefaultContainer(&bstrDefaultContainerPath);

ADsGetObject(bstrDefaultContainerPath,

IID_IADs,

(void**)&pDefaultContainer);

//

// Print the name.

//

pDefaultContainer->get_Name(&bstrName);

printf("%s\n", bstrName);

//

// Cleanup.

//

SysFreeString(bstrDefaultContainerPath);

SysFreeString(bstrName);

pDefaultContainer->Release();

pNamespacesObj->Release();

Example 2: Setting the Default Container (Visual Basic)

Dim NamespacesObj as IADsNamespaces

' Bind to the Namespaces container.

Set NamespacesObj = GetObject("ADS://")

' Set the default container.

NamespacesObj.DefaultContainer = ("WinNT://MyDomain")

Example 2: Setting the Default Container (C/C++)

IADs *pNamespacesObj;

//

// Bind to the Namespaces object.

//

ADsGetObject(TEXT("ADS://"),

IID_IADsNamespaces,

(void**)&pNamespacesObj);

//

// Set the default container.

//

pNamespacesObj->put_DefaultContainer(TEXT("WinNT://MyDomain"));

//

// Cleanup.

//

pNamespacesObj->Release();