Recherche de groupes
Cette rubrique montre comment rechercher des groupes en utilisant DirectorySearcher.
L'exemple C# suivant montre comment rechercher tous les groupes d'un domaine.
using System.DirectoryServices;
...
DirectorySearcher src = new DirectorySearcher(ou,"(objectCategory=group)");
foreach(SearchResult res in src.FindAll())
{
Console.WriteLine(res.Path);
}
L'exemple C# suivant montre comment rechercher tous les groupes sécurisés. Pour cette recherche, utilisez COM InteropUtilisation de COM Interop pour accéder à l'interface ADSI. Pour plus d'informations, voir la rubrique sur l'« interopérabilité COM dans Visual Basic et Visual C# » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252. Cet exemple utilise une recherche par bits.
using System.DirectoryServices;
...
DirectorySearcher src = new DirectorySearcher(ou,"(objectCategory=group)");
int val = (int) ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED;
string query = "(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=" + val.ToString() + "))";
src.Filter = query;
foreach(SearchResult res in src.FindAll())
{
Console.WriteLine(res.Path);
}
L'exemple C# suivant montre comment rechercher tous les groupes d'un domaine global, qu'ils soient sécurisés ou non. Pour cette recherche, utilisez COM InteropUtilisation de COM Interop pour accéder à l'interface ADSI. Pour plus d'informations, voir la rubrique sur l'« interopérabilité COM dans Visual Basic et Visual C# » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252.
using System.DirectoryServices;
...
DirectorySearcher src = new DirectorySearcher(ou,"(objectCategory=group)");
int val = (int) ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP;
string query = "(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=" + val.ToString() + "))";
src.Filter = query;
foreach(SearchResult res in src.FindAll())
{
Console.WriteLine(res.Path);
}
L'exemple C# suivant montre comment rechercher tous les groupes sécurisés d'un domaine global. Pour cette recherche, utilisez COM InteropUtilisation de COM Interop pour accéder à l'interface ADSI. Pour plus d'informations, voir la rubrique sur l'« interopérabilité COM dans Visual Basic et Visual C# » dans MSDN Library à l'adresse https://go.microsoft.com/fwlink/?LinkID=27252.
[C#]
using System.DirectoryServices;
...
DirectorySearcher src = new DirectorySearcher(ou,"(objectCategory=group)");
int val = (int) (ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP
| ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED);
string query = "(&(objectCategory=group)(groupType=" + val.ToString() + "))";
src.Filter = query;
foreach(SearchResult res in src.FindAll())
{
Console.WriteLine(res.Path);
}
Voir aussi
Référence
DirectorySearcher
System.DirectoryServices
Concepts
Send comments about this topic to Microsoft.
Copyright © 2007 par Microsoft Corporation. Tous droits réservés.