Directory Services

Using objectGUID to Bind to an Object

An object distinguished name changes if the object is renamed or moved, therefore the distinguished name is not a reliable object identifier. In Active Directory, an object's objectGUID property is never changed, even if the object is renamed or moved. For more information about objectGUID and identifiers, see Object Names and Identities.

The Active Directory LDAP provider provides a method to bind to an object using the object GUID. The binding string format is as follows:

LDAP://servername/<GUID=XXXXX>

In this example, servername is the name of the directory server and XXXXX is the string representation of the hexadecimal value of the GUID. The servername is optional. The GUID string is specified in the XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX form and is not the same form as the GUID string produced by the StringFromGUID2 function, which takes the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. For more information and a code example that shows how to create a bindable string from a GUID, see Example Code for Creating a Bindable String Representation of a GUID. The IADs::get_GUID method can be used to retrieve the proper string form of the GUID.

When binding using the object GUID, some IADs and IADsContainer methods and properties are not supported. The following IADs properties are not supported by objects obtained by binding using the object GUID:

The following IADsContainer methods are not supported by objects obtained by binding using the object GUID:

To use these methods and properties after binding to an object using the object GUID, use the IADs::Get method to retrieve the object distinguished name and then use the distinguished name to bind to the object again.

If an application stores or caches identifiers or references to objects stored in Active Directory, the object GUID is the best identifier to use for several reasons.

Example Code for Using objectGUID to Bind to an Object

The following Visual Basic code example shows how to use the objectGUID property to bind to an object.

Dim myObject as IADs 
Set myObject = GetObject("LDAP://<GUID=63560110f7e1d111a6bfaaaf842b9cfa>")

The following C++ code example shows how to use the objectGUID property to bind to an object.

IADs *pADs;
LPWSTR pszFilter = L"LDAP://dc08/<GUID=63560110f7e1d111a6bfaaaf842b9cfa>";
hr = ADsGetObject(pszFilter, IID_IADs, (void**)&pADs);