嘿,如何可以通过使用C#的注册表迭代?我希望创建一个表示每个键的属性的结构。C#如何迭代注册表?
8
A
回答
0
这个函数会检索所有子项的名称,您可以遍历它们,做任何你想。
0
您可以使用Microsoft.Win32.RegistryKey
和GetSubKeyNames
方法如下所述:
http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey_members%28v=VS.100%29.aspx
注意的是,如果你是通过注册表的很大一部分迭代,这可能会很慢。
9
我觉得你需要的是GetSubKeyNames()
就像这个例子。
private void GetSubKeys(RegistryKey SubKey)
{
foreach(string sub in SubKey.GetSubKeyNames())
{
MessageBox.Show(sub);
RegistryKey local = Registry.Users;
local = SubKey.OpenSubKey(sub,true);
GetSubKeys(local); // By recalling itself it makes sure it get all the subkey names
}
}
//This is how we call the recursive function GetSubKeys
RegistryKey OurKey = Registry.Users;
OurKey = OurKey.OpenSubKey(@".DEFAULT\test",true);
GetSubKeys(OurKey);
(注:这是从原来的教程http://www.csharphelp.com/2007/01/registry-ins-and-outs-using-c/复制,但该网站现在似乎已关闭)。
+0
谢谢克里斯!我正要编写递归函数,但我不熟悉这些方法! 谢谢 – Tom 2010-05-26 19:23:10
3
private void GetSubKeys(RegistryKey SubKey)
{
foreach(string sub in SubKey.GetSubKeyNames())
{
MessageBox.Show(sub);
RegistryKey local = Registry.Users;
local = SubKey.OpenSubKey(sub,true);
GetSubKeys(local); // By recalling itselfit makes sure it get all the subkey names
}
}
//This is how we call the recursive function GetSubKeys
RegistryKey OurKey = Registry.Users;
OurKey = OurKey.OpenSubKey(@".DEFAULT\test",true);
GetSubKeys(OurKey);
http://www.csharphelp.com/2007/01/registry-ins-and-outs-using-c/
相关问题
- 1. 迭代注册表,查找值
- 2. 项目注册迭代器
- 3. 如何通过C#中的代码编辑Windows注册表值(注册表)?
- 4. 迭代未注册的加载项(.xla)
- 5. C#写注册表
- 6. 如何监视注册表访问? [C#]
- 7. 如何打开注册表和C++
- 8. 如何在C中导出注册表#
- 9. 如何控制与C#或注册表
- 10. C/C + +注册表帮助
- 11. 如何从C#中为代理访问注册表?
- 12. 如何比较C代码注册表中的LONG数据?
- 13. 如何在django注册中注册注册表格
- 14. C#如何注册EXE?
- 15. 如何使用批处理脚本迭代注册表文件夹?
- 16. for循环通过注册表配置单元迭代
- 17. Powershell解析/迭代通过并结合两个注册表项
- 18. 通过注册表子文件夹迭代
- 19. 抽象代表注册
- 20. Lua C++表迭代
- 21. cython - 如何迭代C++列表
- 22. 获取注册表值C#
- 23. C#注册表导入
- 24. C#注册表问题
- 25. C++添加注册表项
- 26. C++ Windows注册表编辑
- 27. C#矩形点注册表
- 28. C++搜索Windows注册表
- 29. C++添加到注册表
- 30. C#注册表权限
这将打破使用Mono任何便携性上的其他系统除了Windows之外。只是一个警告。 – alternative 2010-05-26 19:15:42