共用方式為


具有二進位屬性型別的 DN

部分屬性使用 Object(DN-Binary) 語法類型,例如 Active Directory 結構描述 wellKnownObjects 屬性。如需有關 wellKnownObjects 屬性或 Object(DN-Binary) 語法類型的詳細資訊,請參閱<Well-Known-Objects 屬性>或<Object(DN-Binary)>主題,這些主題位於 MSDN Library,網址為 https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)。

如果使用 Object(DN-Binary) 型別的屬性是使用 Properties 屬性來取得,則此資料型別會以 COM 物件表示,可用 IADsDNWithBinary 介面來存取。如需有關此介面的詳細資訊,請參閱 MSDN Library 中的<IADsDNWithBinary>主題,網址為:https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)。如果使用 Object(DN-Binary) 型別的屬性是從 ResultPropertyValueCollection 所取得,則此資料型別會以 String 物件表示,其中包含以 Object(DN-Binary) 語法所指定之格式表示的辨別名稱與二進位資料。

下列範例示範如何讀取含有使用 DN (以二進位語法表示) 之值的屬性。

Imports ActiveDs

Dim wkObjects As [Object] = usr.Properties("wellKnownObjects").Value
Dim wkObject As DNWithBinary
For Each wkObject In  CType(wkObjects, IEnumerable)
    Dim bytes As Byte() = CType(wkObject.BinaryValue, Byte())
    Dim b As Byte
    For Each b In  bytes
        Console.Write("{0:x2}", b)
    Next b
    Console.WriteLine(wkObject.DNString)
 Next wkObject
using ActiveDs;

Object wkObjects = ent.Properties["wellKnownObjects"].Value;
foreach(DNWithBinary wkObject in (IEnumerable) wkObjects)
{
    byte[] bytes= (byte[]) wkObject.BinaryValue;
    foreach(byte b in bytes)
    {
        Console.Write("{0:x2}",b);
    }
    Console.WriteLine(wkObject.DNString);
}

下列範例示範如何寫入使用 DN (以二進位語法表示) 的屬性值。

Imports ActiveDs

Dim dnBin As New ActiveDs.DNWithBinaryClass()
dnBin.DNString = usr.Properties("distinguishedName").Value.ToString()
dnBin.BinaryValue = usr.Guid.ToByteArray()
usr.Properties("singleDNWithBinary").Value = dnBin
usr.CommitChanges()
using ActiveDs;

ActiveDs.DNWithBinary dnBin = new ActiveDs.DNWithBinaryClass();
dnBin.DNString = usr.Properties["distinguishedName"].Value.ToString();
dnBin.BinaryValue = usr.Guid.ToByteArray();
usr.Properties["singleDNWithBinary"].Value = dnBin;
usr.CommitChanges();

請參閱

參考

System.DirectoryServices
DirectoryEntry
ResultPropertyValueCollection

概念

屬性型別

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.