目錄服務技術介紹——ADSI(六)

來源:互聯網
上載者:User
客戶程式也可以利用IADsClass、IADsProperty和IADsSyntax介面在運行時刻確定目錄對象的詳細屬性資訊。操作步驟如下:
a.    先綁定到目錄對象的表結構對象,可以直接存取目錄對象的“schema”屬性。
b.    用枚舉的辦法從表結構對象中找到強制屬性或者可選屬性,如果客戶知道要訪問的屬性名稱則可以跳過這一步。
c.    綁定到表結構對象的包容器物件。
d.    從表結構對象的包容器物件獲得屬性的定義對象。
e.    從屬性定義對象擷取屬性資訊,包括屬性的文法資訊等。
下面的代碼示範了如何從獲得表結構對象到訪問“Owner”屬性的細節資訊的過程:
Dim obj As IADs
Dim cl As IADsClass
Dim pr As IADsProperty
Dim sy As IADsSyntax
Dim sc As IADsContainer
Set obj = GetObject("WinNT://MyDomain/myMachine")
Set cl = GetObject(obj.Schema)
Set sc = GetObject(cl.Parent)
Set pr = sc.GetObject("Property","Owner")
MsgBox "Attribute: " & pr.Name
MsgBox "Syntax:    " & pr.Syntax
Set sy = GetObject(sc.AdsPath & "/" & pr.Syntax)
MsgBox "Syntax object: " & sy.Name & " of OleAutoDataType: " & sy.OleAutoDataType
(6) 增加或者刪除目錄對象。
利用包容器物件的IADsContainer介面的方法(見表4),我們可以很方便地增加或者刪除目錄對象,舉例如下:
Dim Container as IADsContainer
Dim NewUser as IADsUser
Set Container = GetObject("WinNT://MyDomain")
' Create the new wrapper.
Set NewUser = Container.Create("user", "PanAimin")
' Write it back to the DS
NewUser.SetInfo
' Set Jane's password.
NewUser.SetPassword("123")
' Delete the user.
Call Container.Delete("user","Mary")
ADSI的各種操作比較簡單,只要我們能夠理解ADSI的基本結構,並且對核心的幾個介面以及常用提供者的一些介面有所瞭解,就可以用一致的方法訪問目錄服務,這也說明了ADSI作為通用目錄服務標準為程式員帶來的最大益處。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.