如何列出可用的ADSI(Active Directory服务接口)服务提供商?

时间:2010-08-06 09:15:18

标签: c# .net active-directory directoryservices directoryentry

2 个答案:

答案 0 :(得分:1)

我发现:

foreach (object obj in (IEnumerable)Marshal.BindToMoniker("ADs:"))
{
    obj.GetType().InvokeMember("Name", BindingFlags.DeclaredOnly | 
        BindingFlags.Public | BindingFlags.NonPublic | 
        BindingFlags.Instance | 
        BindingFlags.GetProperty, null, obj, null).Dump();
}   

答案 1 :(得分:0)

Microsoft在此主题上有一个KB-233023:How To Find All ADSI Providers on a System

另一种变体:

    public static IEnumerable<string> GetAdsiProviders()
    {
        var providers = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\ADs\Providers");
        if (null == providers) yield break;

        foreach (var name in providers.GetSubKeyNames())
        {
            yield return name + ":";
        }
    }