IADs 屬性方法

IADs介面的屬性方法會取得或設定下表中所述的屬性。 如需屬性方法的詳細資訊,請參閱 Interface Property Methods

屬性

ADsPath

這個 物件的 ADsPath 字串。 字串可唯一識別網路環境中的這個物件。 一律可以使用這個路徑來擷取物件。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_ADsPath(
  [out] BSTR* pbstrADsPath
);

類別

物件 Schema 類別的名稱。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_Class(
  [out] BSTR* pbstrClass
);

GUID

目錄物件的全域唯一識別碼。 IADs介面會將GUID從八位字串轉換成字串格式,如同儲存在目錄伺服器上一樣。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_GUID(
  [out] BSTR* pbstrGUID
);

名稱

在基礎目錄服務內命名的物件相對名稱。 這個名稱會區分這個物件與其同層級。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_Name(
  [out] BSTR* pbstrName
);

父系

父容器的 ADsPath 字串。 Active Directory 不允許串連 ParentName 屬性來形成指定物件的 ADsPath。 雖然這項作業可能在某些提供者中運作,但並不保證適用于所有實作。 ADsPath 保證有效,而且應該一律用來擷取物件的介面指標。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_Parent(
  [out] BSTR* pbstrParent
);

結構描述

這個物件的 Schema 類別物件的 ADsPath 字串。

存取類型:唯讀

腳本資料類型: BSTR

// C++ method syntax
HRESULT get_Schema(
  [out] BSTR* pbstrSchema
);

備註

在 Active Directory 中,從 GUID 傳回的 GUID 是十六進位字串。 使用產生的 GUID 直接系結至 物件。

Dim x As IADs
Set x = GetObject("LDAP://servername/<GUID=xxx>")

其中 xxx 是 GUID 屬性傳回的值。 如需詳細資訊,請參閱 使用 objectGUID 系結至物件。 請注意,如果您使用 GUID 系結至物件, ADsPath 屬性方法會傳回的值,這與使用辨別名稱 (DN) 系結至相同物件時,會傳回的一般值不同。 例如,下表列出使用兩種不同的系結方法系結至相同使用者物件時所傳回的值。

使用 DN 系結 使用 GUID 系結
名稱 CN=Jeff Smith CN=Jeff Smith
父系 LDAP://server/CN=Users,DC=Fabrikam,DC=com LDAP://server/CN=Users,DC=Fabrikam,DC=com
ADsPath LDAP://server/CN=Jeff Smith,CN=Users,DC=Fabrikam,DC=com <LDAP://server/ GUID=c0f59dfcf507d311a99e0000f879f7c7>

注意

WinNT 提供者不支援使用物件 GUID進行系結,並以稍微不同的字串格式傳回 GUID 屬性。

範例

下列程式碼範例示範如何使用 IADs 介面的屬性方法來擷取物件資料。

Dim x As IADs
Dim parent As IADsContainer
Dim cls As IADsClass
Dim op As Variant

On Error GoTo Cleanup

Set x = GetObject("WinNT://Fabrikam/Administrator")
Debug.Print "Object Name: " & x.Name
Debug.Print "Object Path: " & x.ADsPath
Debug.Print "Object Class: " & x.Class
 
' Get more data about the object schema.
Set cls = GetObject(x.Schema)
Debug.Print "Class Name is: " & cls.Name
For Each op In cls.OptionalProperties
    Debug.Print "Optional Property: " & op
Next op

Cleanup:
    If (Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set x = Nothing
    Set parent = Nothing
    Set cls = Nothing

下列程式碼範例示範如何使用 IADs 介面的屬性方法來擷取物件資料。

<HTML>
<head><title></title></head>

<body>
<%
Dim x 
On Error Resume Next
 
Set x = GetObject("WinNT://Fabrikam/Administrator")
Response.Write "Object Name: " & x.Name & "<br>"
Response.Write "Object Path: " & x.ADsPath & "<br>"
Response.Write "Object Class: " & x.Class & "<br>"
 
' Get more data about the object schema.
Set cls = GetObject(x.Schema)
Response.Write "Class Name is: " & cls.Name & "<br>"
For Each op In cls.OptionalProperties
    Response.Write "Optional Property: " & op & "<br>"
Next op
%>

</body>
</html>

下列程式碼範例示範如何使用 IADs 介面的 屬性方法。

#include <stdio.h>
#include <activeds.h>
 
int main(int argc, char* argv[])
{
    IADs *pADs = NULL;
    IADsUser *pADsUser = NULL;
    IADsClass *pCls = NULL;
    CComBSTR sbstr;
 
    HRESULT hr = CoInitialize(NULL);
    if (hr != S_OK) { return 0; }
 
    hr=ADsGetObject(L"WinNT://Fabrikam/Administrator",
                IID_IADsUser,
                (void**) &pADsUser);
    if (hr != S_OK) { goto Cleanup; }
 
    hr = pADsUser->QueryInterface(IID_IADs, (void**) &pADs);
    if( hr !=S_OK) { goto Cleanup;}
 
    pADsUser->Release();
 
    if( S_OK == pADs->get_Name(&sbstr) ) {
        printf("Object Name: %S\n",sbstr);
    }
 
    if( S_OK == pADs->get_ADsPath(&sbstr) ) {
        printf("Object path: %S\n",sbstr);
    }
 
    if( S_OK == pADs->get_Class(&sbstr) ) {
        printf("Object class: %S\n",sbstr);
    }
 
    hr = pADs->get_Schema(&sbstr);
    if ( hr != S_OK) {goto Cleanup;}
 
    hr = ADsGetObject(sbstr,IID_IADsClass, (void**)&pCls);
    if ( hr != S_OK) {goto Cleanup;}
    if( S_OK == pCls->get_Name(&sbstr) ) {
        printf("Class name is %S\n", sbstr);
    }
 
 Cleanup:
    if(pADs)
        pADs->Release();

    if(pIADsUser)
        pADsUser->Release();

    if(IADsClass)
        pADsClass->Release();

    CoUninitialize();

    if(hr==S_OK)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

規格需求

需求
最低支援的用戶端
Windows Vista
最低支援的伺服器
Windows Server 2008
標頭
Iads.h
DLL
Activeds.dll
IID
IID_IADs定義為 FD8256D0-FD15-11CE-ABC4-02608C9E7553

另請參閱

IADs

IADsContainer