c# - Registry.GetValue() 和 Registry.User.GetValue() 的不同结果

标签 c# registry

我在 output1output2 中得到了不同的结果。第一个给了我在注册表中实际看到的值,而后者只给了我默认值。我想念什么?

String output1 = Registry.GetValue(
  @"HKEY_USERS\blobb", "beep", "nope!") as String;

String output2 = Registry.Users.GetValue(
  @"blobb\beep", "nope!") as String;

我已经尝试了很多不同的输入字符串变体,但没有一个给我正确的值。

最佳答案

Registry.Users.GetValue 正在根 USERS 键中查找名为“blobb\beep”的值

要获得与第一个示例相同的结果,您需要类似的东西

using (var blobb = Registry.Users.OpenSubKey("blobb"))
{
    String output2 = blobb.GetValue("beep", "nope!") as String
}

关于c# - Registry.GetValue() 和 Registry.User.GetValue() 的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13290498/

相关文章:

c++ - 如何编写代码来自动更改注册表值?

c++ - 尝试使用 Windows/C++ 读取注册表值的奇怪错误

c++ - 枚举所有注册表项的最有效方法

c# - 根据字典过滤 XElements 列表

c# - 如何实现延迟位图加载?

c# - 保存到数据库时验证数据字段是否太大?

C# GetMethod 与 GetRuntimeMethod

internet-explorer - 如何从 Windows 注册表中找出安装了 IE 的位置?

c++ - 无法写入注册表

c# - EF Code First - 从 Azure 门户运行更新数据库