获取对象的标识

DirectoryEntry 提供若干用于检索对象的标识的属性。

下面的代码示例说明了如何检索用户对象的 PathGuidName 属性。

try
{
   // Bind to the object for which to retrieve property data.
   DirectoryEntry usr = new DirectoryEntry("LDAP://CN=User Name,OU=HR,DC=fabrikam,DC=com");
   // Retrieve and write the Path for the object.
   Console.WriteLine("Path: {0}", usr.Path);
   // Retrieve and write the Guid for the object.
   Console.WriteLine("Guid: {0}", usr.Guid);
   // Retrieve and write the Name for the object.
   Console.WriteLine("Name: {0}", usr.Name);
   // Retrieve and write the DN for the object.
   Console.WriteLine("DN: {0}", usr.Properties["distinguishedName"].Value);
}
catch
{
   // Add error handling.
}

另请参见

参考

System.DirectoryServices
DirectoryEntry

概念

System.DirectoryServices 入门

Send comments about this topic to Microsoft.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。