Condividi tramite


Ottimizzazione con GetInfoEx

Il metodo IADs.GetInfoEx viene usato per caricare valori di attributo specifici nella cache locale dal servizio directory sottostante. Questo metodo carica solo i valori di attributo specificati nella cache locale. Il metodo IADs.GetInfo viene usato per caricare tutti i valori di attributo nella cache locale.

Il metodo IADs.GetInfoEx ottiene valori correnti specifici per le proprietà di un oggetto Active Directory dall'archivio directory sottostante, aggiornando i valori memorizzati nella cache.

Se nella cache delle proprietà esiste già un valore, tuttavia, la chiamata al metodo IADs.Get o IADs.GetEx senza prima chiamare IADs.GetInfoEx per tale attributo recupererà il valore memorizzato nella cache anziché il valore più corrente dalla directory sottostante. Ciò può causare la sovrascrittura dei valori degli attributi aggiornati se la cache locale è stata modificata, ma i valori non sono stati sottoposti a commit nel servizio directory sottostante con una chiamata al metodo IADs.SetInfo. Il metodo suggerito per evitare problemi di memorizzazione nella cache consiste nel eseguire sempre il commit delle modifiche del valore dell'attributo chiamando IADs.SetInfo prima di chiamare 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

Recupero di attributi costruiti in Active Directory

In Active Directory la maggior parte degli attributi costruiti viene recuperata e memorizzata nella cache quando viene chiamato il metodo IADs.GetInfo (IADs.Get esegue una chiamata IADs.GetInfo implicita se la cache è vuota). Alcuni attributi costruiti, tuttavia, non vengono recuperati e memorizzati nella cache automaticamente e, pertanto, richiedono che il metodo IADs.GetInfoEx venga chiamato in modo esplicito per recuperarli. Ad esempio, in Active Directory, l'attributo canonicalName non viene recuperato quando viene chiamato il metodo IADs.GetInfo e IADs.Get restituirà E_ADS_PROPERTY_NOT_FOUND. Il metodo IADs.GetInfoEx deve essere chiamato per recuperare l'attributo canonicalName . Questi stessi attributi costruiti non verranno recuperati anche usando l'interfaccia IADsPropertyList per enumerare gli attributi.

Per altre informazioni e un esempio di codice che illustra come recuperare tutti i valori degli attributi, vedere Codice di esempio per la lettura di un attributo costruito.