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

Optimization Using GetInfoEx

· 52CE 我爱测

Used to load specific attribute values into the local cache from the underlying directory service.

The IADs.GetInfoEx method is used to load specific attribute values into the local cache from the underlying directory service. This method only loads the specified attribute values into the local cache. The IADs.GetInfo method is used to load all attribute values into the local cache.

The IADs.GetInfoEx method gets specific current values for the properties of an Active Directory object from the underlying directory store, refreshing the cached values.

If a value already exists in the property cache, however, calling the IADs.Get or IADs.GetEx method without first calling IADs.GetInfoEx for that attribute will retrieve the cached value rather than the most current value from the underlying directory. This can cause updated attribute values to be overwritten if the local cache has been modified, but the values have not been committed to the underlying directory service with a call to the IADs.SetInfo method. The suggested method for avoiding caching problems is to always commit attribute value changes by calling IADs.SetInfo before calling IADs.GetInfo.

Dim usr As IADs
Dim PropArray As Variant

On Error GoTo Cleanup

' Bind to a specific user object.
Set usr = GetObject("LDAP://CN=Jeff Smith,CN=Users,DC=fabrikam,DC=com")
 
' The code example assumes that the property description has a single value in the directory.
' Be aware that this will implicitly call GetInfo because, at this point, GetInfo
' has not yet been called (implicitly or explicitly) on the usr object.
Debug.Print "User's common name is " + usr.Get("cn")
Debug.Print "User's title is " + usr.Get("title")
Debug.Print "User's department is " + usr.Get("department")

' Change two of the attribute values in the local cache.
usr.Put "cn", "Jeff Smith"
usr.Put "title", "Vice President"
usr.Put "department", "Head Office"
Debug.Print "User's common name is " + usr.Get("cn")
Debug.Print "User's title is " + usr.Get("title")
Debug.Print "User's department is " + usr.Get("department")

' Initialize the array of properties to pass to GetInfoEx.
PropArray = Array("department", "title")
 
' Get the specified attribute values.
usr.GetInfoEx PropArray, 0

' The specific attributes values were overwritten, but the attribute
' value not retrieved has not changed.
Debug.Print "User's common name is " + usr.Get("cn")
Debug.Print "User's title is " + usr.Get("title")
Debug.Print "User's department is " + usr.Get("department")

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

Retrieving Active Directory Constructed Attributes

In Active Directory, most of the constructed attributes are retrieved and cached when the IADs.GetInfo method is called (IADs.Get performs an implicit IADs.GetInfo call if the cache is empty). Some constructed attributes, however, are not automatically retrieved and cached and, therefore, require that the IADs.GetInfoEx method be called explicitly to retrieve them. For example, in Active Directory, the canonicalName attribute is not retrieved when the IADs.GetInfo method is called and IADs.Get will return E_ADS_PROPERTY_NOT_FOUND. The IADs.GetInfoEx method must be called to retrieve the canonicalName attribute. These same constructed attributes will also not be retrieved using the IADsPropertyList interface to enumerate the attributes.

For more information and a code example that shows how to retrieve all attribute values, see Example Code for Reading a Constructed Attribute.

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)

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

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