大网数据广告活动
域与目录服务

Accessing Attributes with ADSI

· 52CE 我爱测

The IADs.Get and IADs.GetEx methods are used to retrieve named attribute values.

The IADs.Get and IADs.GetEx methods are used to retrieve named attribute values. Both methods return a VARIANT value. These methods are available only for directories that support a schema. When accessing objects in a directory without a schema, the IADsPropertyEntry and IADsPropertyValue interfaces must be used to manipulate attribute values.

The IADs.Get and IADs.GetEx methods return a VARIANT which may, or may not, be a VARIANT array depending on the number of values returned by the server. For example, if only one value is returned from the server, regardless of whether it is a single or multi-valued attribute, the method returns a single VARIANT. Conversely, if multiple values are returned, a VARIANT array is returned. If a VARIANT array is returned, the vt member of the VARIANT structure contains the VT_VARIANT/vbVariant and VT_ARRAY/vbArray flags.

The IADs.Get and IADs.GetEx methods can also return a COM object using the IDispatch interface. In this case, the vt member of the VARIANT structure contains the VT_DISPATCH/vbObject flag. To access the COM object, call the QueryInterface method on the IDispatch interface to obtain the desired interface.

Another data type returned by the IADs.Get and IADs.GetEx methods is binary data. In this case, the data is supplied as a contiguous array of bytes and the vt member of the VARIANT structure will contain the VT_UI1/vbByte and VT_ARRAY/vbArray flags.

Note:
Microsoft Visual Basic, Scripting Edition only supports VARIANT and VARIANT arrays. Because of this, VBScript cannot be used to read binary property values.

Many ADSI interfaces define interface-specific properties. For example, the IADsComputer interface defines the Location property. These interface-defined properties may contain data that is identical to one of the named attributes, but the properties are specific to the type of object the interface refers to. In languages that support automation, these interface-defined properties can be accessed using the dot notation as shown in the following code example.

Examples

The following code example shows how to access the ADsPath property on the IADs interface.

Dim oUser as IADs
Dim Path as String
 
' Bind to a specific user object.
set oUser = GetObject(
            "LDAP://CN=Jeff Smith,CN=Users,DC=fabrikam,DC=com")
 
' Get property.
Path = MyUser.ADsPath

In non-automation languages, the property access methods must be used to access the interface-defined properties. For example, the IADsComputer::get_Location method is used to retrieve the IADsComputer.Location property.

The following C++ code example demonstrates how to use the property access method in C++ to retrieve the ADsPath of a user.

HRESULT hr;
IADs *pUser; 
 
// Bind to user object.
hr = ADsGetObject(
     L"LDAP://CN=Jeff Smith,CN=Users,DC=fabrikam,DC=com", 
     IID_IADs, 
     (void**)&pUser);
if(SUCCEEDED(hr)) 
{
    BSTR bstrName;

    // Get property.
    hr = pUser->get_Name(&bstrName);
    if(SUCCEEDED(hr)) 
    {
        wprintf(bstrName);
 
        SysFreeString(bstrName);
    }

    pUser->Release();
}

For more information about accessing attributes with ADSI, see:

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。