Original URL: | https://blogs.msdn.microsoft.com/alejacma/2008/03/25/how-to-get-ads-providers-list-c/ |
Post name: | How to get ADs Providers list (C#) |
Original author: | Alejandro Campos Magencio |
Posting date: | 2008-03-25T12:30:00+00:00 |
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)
Comments: