如何使用 Microsoft.Win32.Registry.OpenSubKey 直接转到特定密钥?

发布于 2024-11-30 15:42:05 字数 372 浏览 0 评论 0原文

这是一个简单的问题。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囚你心 2024-12-07 15:42:06

我认为您期望 OpenSubKey() 方法对 reg 执行某些操作 - 以某种方式使其指向子密钥。事实并非如此。 OpenSubKey() 返回一个RegistryKey 类型的新对象,可用于检索子项的值或修改子项。所以你需要:

RegistryKey reg = Registry.LocalMachine;
RegistryKey subKey = reg.OpenSubKey(@"Software\Microsoft", true);  

I think you are expecting the OpenSubKey() method to do something to reg - 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:

RegistryKey reg = Registry.LocalMachine;
RegistryKey subKey = reg.OpenSubKey(@"Software\Microsoft", true);  
无所的.畏惧 2024-12-07 15:42:06

OpenSubKey 返回新的 RegistryKey对象:

reg = reg.OpenSubKey(@"Software\Microsoft", true); // Will work or
var sub = reg.OpenSubKey(@"Software\Microsoft", true);

OpenSubKey returns a new RegistryKey object :

reg = reg.OpenSubKey(@"Software\Microsoft", true); // Will work or
var sub = reg.OpenSubKey(@"Software\Microsoft", true);
风吹短裙飘 2024-12-07 15:42:06

当然只需输入该密钥的完整路径,例如:

Registry.CurrentUser.OpenSubKey("the registry full path");

Sure just put your full path of that key, example:

Registry.CurrentUser.OpenSubKey("the registry full path");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文