GetEx 方法

某些属性可以存储一个或多个值。 例如,Active Directory 中用户对象的 otherTelephone 属性是一个可以具有零、一个或多个值的属性。 具有多个值的属性称为“多值属性”。 如果使用 IADs::Get 方法检索多值属性,则结果的处理方式必须与该属性具有单个值时不同。 但是,无论属性是单个值还是多个值,IADs::GetEx 方法提供的结果都以相同的方式处理。 在这两种情况下,IADs::GetEx 方法都返回数组中的值。

IADs::GetEx 方法从属性缓存中检索属性。 如果在缓存中找不到指定的属性,IADs::GetEx 将执行隐式 IADs::GetInfo 调用。

无论从服务器返回的值数如何,IADs::GetEx 方法都会返回变量的变量数组。 即使属性仅包含一个值,也是如此。

Dim usr As IADs
On Error GoTo Cleanup

Set usr = GetObject("LDAP://CN=Jeff Smith,CN=Users,DC=fabrikam,DC=com")
homePhones = usr.GetEx("otherHomePhone")
For each phone in homePhones
    Debug.Print phone
Next

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

IADs::GetEx 方法也可用于单值属性。 对单值属性的结果的处理与对多值属性的处理相同。

Dim usr as IADs
On Error GoTo Cleanup

Set usr = GetObject("LDAP://CN=Jeff Smith,CN=Users,DC=fabrikam,DC=com")
sds = usr.GetEx("ntSecurityDescriptor")
For each sd in sds
    Set acl = sd.DiscretionaryACL
Next

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

如果未为属性设置值,则 IADs::GetEx 将返回错误“缓存中未找到该属性”。