Welcome to MSDN Blogs Sign in | Join | Help

Decrypt my World

Cryptography, Security, Debugging and more!

News

  • Any of my posts is supported under any Microsoft standard support program or service. They are provided "AS IS" without warranty of any kind, and confer no rights.

Where are my readers?

Locations of visitors to this page

Favorite Posts

How to get ADs Providers list (C#)

Hi, welcome back, 

We may want to get the list of Active Directory Providers ("LDAP:", "WinNT:", "IIS:"...) with .NET the same way we do it with this VBScript:

Set ads = GetObject("ADs:")
For Each provider In ads
    Wscript.Echo provider.Name
Next

The information we need is here in the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ADs\Providers. So the following sample code will get the info we need:

using Microsoft.Win32;

...

    // Get the HKLM registry key
    RegistryKey RegKey = Registry.LocalMachine;

    // Open the sub-key which contains all the providers
    RegistryKey ProviderKey = RegKey.OpenSubKey(@"Software\Microsoft\ADs\Providers");

    // Get the list of the sub-keys
    string[] SubKeys = ProviderKey.GetSubKeyNames();

    // Create the string array which will hold the provider list
    string[] ListOfProviders = new string[SubKeys.Length];

    // Now add all providers to the array
    for (int Count = 0; Count < SubKeys.Length; Count++)
    {
        ListOfProviders[Count] = SubKeys[Count] + ":";
    }

    // Show the list of providers
    foreach (string providerName in ListOfProviders)
    {
        MessageBox.Show(providerName);
    }
...

I hope this helps.

Cheers,

 

Alex (Alejandro Campos Magencio)

Posted: Tuesday, March 25, 2008 5:30 PM by alejacma

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker