Loop through all subkeys contained in the current key : Registry Read « Windows « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / CSharp Tutorial » Windows » Registry Read 
29.1.3.Loop through all subkeys contained in the current key
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);
        }
    }
}
29.1.Registry Read
29.1.1.Get int value from Registry
29.1.2.Get Registry values with default
29.1.3.Loop through all subkeys contained in the current key
29.1.4.Loop through the values inside a key and display
29.1.5.Registry Tree
29.1.6.Registry Tree With Class
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.