Partager via


Appel des méthodes de l'interface ADSI

Si une interface ADSI prend en charge l'interface IDispatch, vous pouvez utiliser la méthode Invoke pour accéder aux méthodes de cette interface. Cela s'applique également à toute extension ADSI que vous avez ajoutée précédemment. Vous n'avez pas besoin d'inclure la bibliothèque ADSI pour utiliser la méthode Invoke.

Lorsqu'une méthode sous-jacente échoue, une exception TargetInvocationException peut être levée. La propriété InnerException de l'objet TargetInvocationException est un objet COMException qui contient des informations sur l'erreur qui s'est produite.

L'exemple C# suivant indique comment appeler la méthode SetPassword de l'interface IADsUser pour définir un mot de passe. Pour plus d'informations sur l'interface IADsUser ou la méthode SetPassword, voir les rubriques « IADsUser » ou « IADsUser::SetPassword » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252.

DirectoryEntry usr = new DirectoryEntry("LDAP://CN=John Smith, DC=Fabrikam,DC=COM");
usr.Invoke("SetPassword", new object[] {SecurelyStoredPassword});

L'exemple C# suivant indique comment appeler la méthode ChangePassword de l'interface IADsUser pour changer un mot de passe. Pour plus d'informations sur l'interface IADsUser ou la méthode ChangePassword, voir les rubriques « IADsUser » ou « IADsUser::ChangePassword » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252.

DirectoryEntry usr = new DirectoryEntry("LDAP://CN=John Smith, DC=Fabrikam,DC=COM");
usr.Invoke("ChangePassword", new object[] {SecurelyStoredPassword, NewSecurelyStoredPassword});

L'exemple C# suivant indique comment appeler la méthode Members de l'interface IADsGroup pour récupérer les membres d'un groupe. Pour plus d'informations sur l'interface IADsGroup ou la méthode Members, voir les rubriques « IADsGroup » ou « IADsGroup::Members » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252.

DirectoryEntry grpEntry = new DirectoryEntry("LDAP://CN=Enterprise Admins,CN=Users,DC=Fabrikam, DC=com");
object members = grpEntry.Invoke("Members",null);
foreach( object member in (IEnumerable) members)
{
    DirectoryEntry x = new DirectoryEntry(member);
    Console.WriteLine(x.Name);
}

Voir aussi

Référence

System.DirectoryServices
DirectoryEntry
TargetInvocationException
COMException
TargetInvocationException

Concepts

Appel d'ADSI

Send comments about this topic to Microsoft.

Copyright © 2007 par Microsoft Corporation. Tous droits réservés.