Richiamo di proprietà ADSI

Esistono due modi per accedere direttamente alle proprietà di un oggetto ADSI COM. Il primo consiste nell'utilizzare il metodo InvokeMember. Il secondo consiste nell'utilizzare i metodi InvokeGet e InvokeSet, novità di Microsoft .NET Framework versione 2.0.

Nell'esempio di codice C# riportato di seguito viene illustrato come utilizzare il metodo InvokeMember per recuperare le proprietà IADSUser, FirstName e LastName da un'applicazione con codice gestito. Per ulteriori informazioni su queste proprietà, vedere gli argomenti relativi a IADsUser, FirstName e LastName in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

using System.Reflection;
using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
Object ads = ent.NativeObject;
Type type = ads.GetType();
String firstName = (string)type.InvokeMember(
    "FirstName", 
    BindingFlags.GetProperty, 
    null, 
    ads, 
    null);
String lastName = (string)type.InvokeMember(
    "LastName", 
    BindingFlags.GetProperty, 
    null, 
    ads, 
    null);

Nell'esempio di codice Visual Basic riportato di seguito viene illustrato come utilizzare il metodo InvokeMember per recuperare le proprietà IADSUser, FirstName e LastName da un'applicazione con codice gestito. Per ulteriori informazioni su queste proprietà, vedere gli argomenti relativi a IADsUser, FirstName e LastName in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

Imports System.Reflection
Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim ads As [Object] = ent.NativeObject
Dim type As Type = ads.GetType()
Dim firstName As String = CStr(type.InvokeMember( _
    "FirstName", _
    BindingFlags.GetProperty, _
    Nothing, _
    ads, _
    Nothing))
Dim lastName As String = CStr(type.InvokeMember( _
    "LastName", _
    BindingFlags.GetProperty, _
    Nothing, _
    ads, _
    Nothing))

Nell'esempio di codice C# riportato di seguito viene illustrato come utilizzare il metodo InvokeGet per recuperare le proprietà IADSUser, FirstName e LastName da un'applicazione con codice gestito. Per ulteriori informazioni su queste proprietà, vedere gli argomenti relativi a IADsUser, FirstName e LastName in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

.

using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
String firstName = (string)ent.InvokeGet("FirstName");
String lastName = (string)ent.InvokeGet("LastName");

Nell'esempio di codice Visual Basic riportato di seguito viene illustrato come utilizzare il metodo InvokeGet per recuperare le proprietà IADSUser, FirstName e LastName da un'applicazione con codice gestito. Per ulteriori informazioni su queste proprietà, vedere gli argomenti relativi a IADsUser, FirstName e LastName in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim firstName As String = CStr(ent.InvokeGet("FirstName"))
Dim lastName As String = CStr(ent.InvokeGet("LastName"))

Nell'esempio di codice C# riportato di seguito viene illustrato come utilizzare il metodo InvokeMember per impostare la proprietà Description di un oggetto.

using System.Reflection;
using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
Object ads = ent.NativeObject;
Type type = ads.GetType();
type.InvokeMember("Description", 
    BindingFlags.SetProperty, 
    null, 
    ads, 
    new object[] {"some description"});

// The changes to the object must always be committed or else they 
// will be lost.
ent.CommitChanges(); 

Nell'esempio di codice Visual Basic riportato di seguito viene illustrato come utilizzare il metodo InvokeMember per impostare la proprietà Description di un oggetto.

Imports System.Reflection
Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim ads As [Object] = ent.NativeObject
Dim type As Type = ads.GetType()
type.InvokeMember("Description", _
    BindingFlags.SetProperty, _
    Nothing, _
    ads, _
    New Object() {"some description"})

' The changes to the object must always be committed or else they 
' will be lost.
ent.CommitChanges()

Nell'esempio di codice C# riportato di seguito viene illustrato come utilizzare il metodo InvokeSet per impostare la proprietà Description di una voce di directory. Per ulteriori informazioni sulla proprietà Description, vedere l'argomento relativo in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
ent.InvokeSet("Description", new object[] {"some description"});

// The changes to the object must always be committed or else they 
// will be lost.
ent.CommitChanges();

Nell'esempio di codice Visual Basic riportato di seguito viene illustrato come utilizzare il metodo InvokeSet per impostare la proprietà Description di una voce di directory. Per ulteriori informazioni sulla proprietà Description, vedere l'argomento relativo in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese).

Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
ent.InvokeSet("Description", New Object() {"some description"})

' The changes to the object must always be committed or else they 
' will be lost.
ent.CommitChanges()

Vedere anche

Riferimenti

System.DirectoryServices
DirectoryEntry
Type

Concetti

Richiamo di ADSI

Send comments about this topic to Microsoft.

Copyright © 2007 Microsoft Corporation. Tutti i diritti riservati.