快速的方式来阅读所有注册表值 [英] Fast way to read all registry values

查看:136
本文介绍了快速的方式来阅读所有注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个需要创造HKCR所有注册表值的列表的工具。我使用的是递归函数这样做:

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());
    }
}

这工作得很好,但它需要时间的很大一部分(20秒我的电脑)。有没有更快的方法来做到这一点,或者这是爱在心里口难开?

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?

推荐答案

有大量的信息在注册表中,正如其他人在这里指出的 - 速度可能是一个问题。如果你想的注册表设置列表的树状视图为用户显示浏览,更好的解决方案可能是扫描顶层条目,再为用户浏览树,让您扫描的那些子值/设置树节点被打开。

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.

这篇关于快速的方式来阅读所有注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆