GetInfoExを使用した最適化
IADs.GetInfoExメソッドは、基礎となるディレクトリサービスからローカルキャッシュに特定の属性値をロードするために使用されます。 このメソッドは、指定された属性値のみをローカルキャッシュに読み込みます。 IADs.GetInfoメソッドは、すべての属性値をローカルキャッシュにロードするために使用されます。
IADs.GetInfoExメソッドは、基礎となるディレクトリストアからActive Directoryオブジェクトのプロパティの特定の現在の値を取得し、キャッシュされた値をリフレッシュします。
しかし、値がすでにプロパティ・キャッシュに存在する場合、その属性に対して最初にIADs.GetInfoExを呼び出さずにIADs.GetまたはIADs.GetExメソッドを呼び出すと、基礎となるディレクトリから最新の値ではなく、キャッシュされた値を取得します。 これにより、ローカル キャッシュが変更されたが、値が IADs::SetInfo メソッドの呼び出しによって基になるディレクトリ サービスにコミットされていない場合、更新された属性値が上書きされる可能性があります。 IADs.GetInfoを呼び出す前に、IADs.SetInfoを呼び出して、属性値の変更を常にコミットすることが、キャッシュ問題を回避するための推奨される方法です。
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
Active Directoryで構築された属性の取得
Active Directoryでは、IADs.GetInfoメソッドが呼び出されると、構築された属性のほとんどが取得され、キャッシュされます(IADs.Getは、キャッシュが空の場合、暗黙のIADs.GetInfo呼び出しを実行します)。 ただし、一部の構築された属性は自動的に取得およびキャッシュされないため、IADs.GetInfoExメソッドを明示的に呼び出して取得する必要があります。 例えば、Active Directoryでは、IADs.GetInfoメソッドを呼び出すと canonicalName属性は取得されず、IADs.GetはE_ADS_PROPERTY_NOT_FOUNDを返します。 canonicalName 属性を取得するには、IADs.GetInfoEx メソッドを呼び出す必要があります。 属性を列挙するためにIADsPropertyListインターフェイスを使用しても、これらの同じ構築された属性は取得されません。
すべての属性値を取得する方法を示すコード例と詳細については、 構築された属性を読み取るためのコード例を参照してください。