本文介绍了Registry.GetValue怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图获取注册表值:var value = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography", "MachineGuid", 0);在Windows XP中一切正常,但在Windows 7中返回0。在 HKEY_LOCAL_MACHINE软件Microsoft\密码学使用regedit我看到 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 runvar keys = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Cryptography", RegistryKeyPermissionCheck.ReadSubTree).GetValueNames(); 键。长度为0。我做错了什么?推荐答案问题是,如果您将解决方案编译为x86,则问题是The problem is that you probably are compiling the solution as x86, if you compile as x64 you can read the values.尝试将以下代码编译为x86和x64:Try the following code compiling as x86 and x64:class Program{ static void Main(string[] args) { Console.WriteLine("MachineGUID:" + MachineGUID); Console.ReadKey(); } public static string MachineGUID { get { Guid guidMachineGUID; if (Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography") != null) { if (Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography").GetValue("MachineGuid") != null) { guidMachineGUID = new Guid(Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography").GetValue("MachineGuid").ToString()); return guidMachineGUID.ToString(); } } return null; } }}您可以阅读有关访问备用注册表视图。您可以在此处一种在x86和x64中读取值的方法。You can found in here a way of reading values in x86 and x64. 这篇关于Registry.GetValue怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-09 18:38