Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OpenSubKey()为我在regedit.exe中看到的注册表项返回null_C#_Registry - Fatal编程技术网

C# OpenSubKey()为我在regedit.exe中看到的注册表项返回null

C# OpenSubKey()为我在regedit.exe中看到的注册表项返回null,c#,registry,C#,Registry,我正在尝试获取此键中所有子键的显示名称: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 使用此代码: 注册表键newKey; 字符串val; 字符串KeyPath64Bit=@“软件\Microsoft\Windows\CurrentVersion\Uninstall”; RegistryKey mainKey=Registry.LocalMachine.OpenSubKey(KeyPath64位)

我正在尝试获取此键中所有子键的显示名称:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
使用此代码:

注册表键newKey;
字符串val;
字符串KeyPath64Bit=@“软件\Microsoft\Windows\CurrentVersion\Uninstall”;
RegistryKey mainKey=Registry.LocalMachine.OpenSubKey(KeyPath64位);
string[]RegKeys64Bits=Registry.LocalMachine.OpenSubKey(KeyPath64Bit.GetSubKeyNames();
foreach(以RegKeys64位表示的字符串s)
{
newKey=mainKey.OpenSubKey;
val=newKey.GetValue(“DisplayName”、-1,RegistryValueOptions.None).ToString();
如果(val!=“-1”)
file64.WriteLine(val);
}
运行代码后,我找不到所需的密钥之一:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}

它应该具有显示名称:微软Visual C++ 2010 X64可重新分发-100.30319,但是代替<代码> GETSub KeNyMeSe()/Script >方法给了我子关键字:<代码> {DA5E37 1C-633-3D8A 93A4-6FD5B20BC66}。KB2151757 < /代码>没有任何显示名称。


为什么我不能得到我所需要的确切的子密钥(
{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}
)以及如何获得它?

一个64位操作系统上的32位应用程序默认情况下会查看
HKLM\Software\Wow6432Node
节点。要读取64位版本的密钥,需要指定
注册表视图

using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"))
{
   // key now points to the 64-bit key
}
在.NET4.0中添加了实现这一点的API;如果仍在使用3.5,则需要使用P/Invoke访问64位密钥:

在Visual Studio 2017中转到

Project > Properties > Build > Uncheck 32 bit and Platform target as "Any CPU".

如果您以管理员身份运行visual studio,您可以这样做吗?@tsells尝试过,但不起作用。您是否在64位操作系统上运行32位进程?@RichardDeeming可执行文件编译为32位,而我的操作系统为64位。我也有同样的问题,用同样的钥匙。:)谢谢你。虽然我仍然不明白为什么有两个注册表。@RobertNoack:我认为它主要用于COM,并确保环境变量在
REG\u EXPAND\u SZ
值中正确展开。MSDN上有一些信息-你救了我一天。我被注册表项对我的行为方式吓坏了+1.我一定读过十几本解释书;这是第一个显示RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,RegistryView.Registry64))步骤。谢谢我也有同样的问题-我没有检查32位,它工作得很好。