Loop through the values inside a key and display : Registry Read : Windows C# Examples


C# Examples » Windows » Registry Read »

 

Loop through the values inside a key and display









    
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)  {
                                                foreach  (string  valuename  in  key.GetValueNames())
                                                {
                                                        if  (key.GetValue(valuename)  is  String)
                                                        {
                                                                Console.WriteLine("    Value  :  {0}  =  {1}",
                                                                        valuename,  key.GetValue(valuename));
                                                        }
                                                }
                                        }
                                        SearchSubKeys(key,  searchKey);
                                }
                        }
                        catch  (System.Security.SecurityException)
                        {
                        }
                }
        }

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




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Windows
» Registry Read