Binding Using GUID

Since directory objects are sometimes moved, the distinguished name to the object may change to reflect the new path to the object. If you need to maintain a reference to an object for an application, then you may want to use the GUID to bind to the object. This topic shows how to retrieve a GUID and rebind to the object using that GUID.

To retrieve the GUID assigned to an object, use the NativeGuid property provided by the DirectoryEntry class. The following code example shows how to use the NativeGuid property.

Dim ent As New DirectoryEntry()
Dim ADGuid As [String] = ent.NativeGuid
' Rebind using ADGuid.
Dim x As New DirectoryEntry("LDAP://<GUID=" + ADGuid + ">")
Console.WriteLine("These should be the same: {0} == {1}", ent.Name, x.Name)
DirectoryEntry ent = new DirectoryEntry();
String ADGuid = ent.NativeGuid;
// Rebind using ADGuid.
DirectoryEntry x = new DirectoryEntry("LDAP://<GUID="+ADGuid+">");
Console.WriteLine("These should be the same: {0} == {1}", ent.Name,x.Name);

See Also

Reference

System.DirectoryServices
DirectoryEntry

Concepts

Binding to Directory Objects

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.