user27414
user27414

Reputation:

Fast way to read all registry values

I'm writing a utility that needs to create a list of all registry values in HKCR. I am doing this using a recursive function:

var list = new Dictionary<string, string>();
Read(Registry.ClassesRoot, list);

static void Read(RegistryKey root, IDictionary<string, string> values)
{
    foreach (var child in root.GetSubKeyNames())
    {
        using (var childKey = root.OpenSubKey(child))
        {
            Read(childKey, values);
        }
    }            

    foreach (var value in root.GetValueNames())
    {
        values.Add(string.Format("{0}\\{1}", root, value), (root.GetValue(value) ?? "").ToString());
    }
}

This works fine, but it takes a good chunk of time (20 seconds on my PC). Is there a faster way to do this, or is this as good as it gets?

Upvotes: 7

Views: 4527

Answers (1)

Swomble
Swomble

Reputation: 909

There's a lot of information in the registry and as others have noted here - speed can be an issue. If you want a list of registry settings to display in a tree-like view for the user to browse through, a better solution might be to scan the top level entries first, then as the user navigates through the tree, so you scan for those child values/settings as the tree node is opening.

I suspect this is how Microsoft's own regedit works.

Upvotes: 1

Related Questions