如何使用 Microsoft.Win32.Registry.OpenSubKey 直接转到特定密钥?
这是一个简单的问题。 MSDN 中应该有明确的记录。我找了找,但没找到。我得到的唯一结果是,我必须一个又一个地打开子键才能找到我感兴趣的特定键。
当然有一种更直接的方法来访问 3 层深度的键。它是什么?
我已经尝试过
RegistryKey reg = Registry.LocalMachine;
reg.OpenSubKey(@"Software\Microsoft", true); // reg is still HKLM !
了
reg.OpenSubKey(@"Software\Microsoft\", true); // reg is still HKLM !
Now this is a simple question. It should be clearly documented in MSDN. I looked but I couldn't find it. The only thing I got was that I had to open subkey after subkey after subkey to get to the particular key I'm interested in.
Surely there is a more direct method to access a key 3 levels deep. What is it?
I've already tried
RegistryKey reg = Registry.LocalMachine;
reg.OpenSubKey(@"Software\Microsoft", true); // reg is still HKLM !
and
reg.OpenSubKey(@"Software\Microsoft\", true); // reg is still HKLM !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您期望
OpenSubKey()
方法对reg
执行某些操作 - 以某种方式使其指向子密钥。事实并非如此。OpenSubKey()
返回一个RegistryKey 类型的新对象,可用于检索子项的值或修改子项。所以你需要:I think you are expecting the
OpenSubKey()
method to do something toreg
- somehow to make it point to the sub key. It doesn't work that way.OpenSubKey()
returns a new object of type RegistryKey which can be used to retrieve the value of, or modify, the sub key. So you need:OpenSubKey
返回新的RegistryKey对象:
OpenSubKey
returns a newRegistryKey
object :当然只需输入该密钥的完整路径,例如:
Sure just put your full path of that key, example: