RegistryKey.GetSubKeyNames() : RegistryKey « Microsoft.Win32 « C# / C Sharp by API






RegistryKey.GetSubKeyNames()

  
using System;
using Microsoft.Win32;

class MainClass
{
    public static void SearchSubKeys(RegistryKey root, String searchKey)
    {
        
        foreach (string keyname in root.GetSubKeyNames())
        {
            try
            {
                using (RegistryKey key = root.OpenSubKey(keyname))
                {
                    if (keyname == searchKey) 
                        Console.WriteLine("Registry key found : {0} contains {1} values",
                            key.Name, key.ValueCount);
                       
                    SearchSubKeys(key, searchKey);
                }
            }
            catch (System.Security.SecurityException)
            {
            }
        }
    }

    public static void Main(String[] args)
    {
        using (RegistryKey root = Registry.CurrentUser)
        {
            string myKey="Java";
            SearchSubKeys(root, myKey);
        }
    }
}

   
    
  








Related examples in the same category

1.RegistryKey.Close()
2.RegistryKey.CreateSubKey(String value)
3.RegistryKey.GetValue
4.RegistryKey.OpenSubKey
5.RegistryKey.SetValue