请告诉我错Registry.GetValue?

编程入门 行业动态 更新时间:2024-10-25 07:32:18
本文介绍了请告诉我错Registry.GetValue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图让一个注册表值:

I trying to get a registry value:

var value = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography", "MachineGuid", 0);

在Windows XP中都可以,但是在Windows 7返回0。 HKEY_LOCAL_MACHINE \ SOFTWARE \微软\加密使用注册表编辑器我看到的MachineGuid ,但如果我跑

In Windows XP all ok, but in Windows 7 returns 0. In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography using regedit I see MachineGuid, but if I run

var keys = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Cryptography", RegistryKeyPermissionCheck.ReadSubTree).GetValueNames();

keys.Length 0

我该怎么办错了吗?与其他值都可以在这两个操作系统。

What do I do wrong? With other values all ok in both of OS.

推荐答案

如果你不是一个管理员,你只有读取HKLM权限。你需要开关键只读代替。不知道怎么做,与.NET的注册类;直接的API,可以使用 RegOpenKeyEx的()与 KEY_READ 标记。

编辑:检查MSDN之后,我看到 OpenSubKey()不以只读方式打开,并返回的内容,如果它成功,仅此而已,如果它失败。既然你链接多个OpenSubKey调用,这是最有可能他们中的一个说是失败,导致其他失败。尝试打破他们分为不同的电话,并检查中间值返回。

After checking MSDN, I see that OpenSubKey() does open read only, and returns the contents if it succeeds and nothing if it fails. Since you're chaining multiple OpenSubKey calls, it's most likely one of them that's failing that causes the others to fail. Try breaking them out into separate calls, and checking the intermediate values returned.

更多推荐

请告诉我错Registry.GetValue?

本文发布于:2023-11-09 10:06:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:告诉我   Registry   GetValue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!