使用 GUID 繫結

由於目錄物件有時候會移動,所以物件的辨別名稱可能會變更,以反映物件的新路徑。若您需要為應用程式維持物件的參照,則可能要使用 GUID 來繫結物件。本主題示範如何擷取 GUID,然後使用該 GUID 繫結物件。

若要擷取指派給物件的 GUID,請使用 NativeGuid 屬性,此屬性由 DirectoryEntry 類別提供。下列程式碼範例示範如何使用 NativeGuid 屬性。

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);

請參閱

參考

System.DirectoryServices
DirectoryEntry

概念

繫結至目錄物件

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.