OpenSubKey()的注册表项,我可以在REGEDIT.EXE看到返回null [英] OpenSubKey() returns null for a registry key that I can see in regedit.exe

查看:391
本文介绍了OpenSubKey()的注册表项,我可以在REGEDIT.EXE看到返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这个关键中的子键的所有显示名称:

I'm trying to get all the display names of the sub keys within this key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

有了这个code:

With this code:

     RegistryKey newKey;
     string val;

     string KeyPath64Bit = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
     RegistryKey mainKey = Registry.LocalMachine.OpenSubKey(KeyPath64Bit);

     string[] RegKeys64Bits = Registry.LocalMachine.OpenSubKey(KeyPath64Bit).GetSubKeyNames();

     foreach (string s in RegKeys64Bits)
     {
        newKey = mainKey.OpenSubKey(s);
        val = newKey.GetValue("DisplayName", -1, RegistryValueOptions.None).ToString();
        if (val != "-1")
           file64.WriteLine(val);
     }

运行code后,我无法找到我需要的关键之一:

After running the code I can't find one of the keys I need:

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

和它应该有显示名称:微软的Visual C ++ 2010可再发行64 - 10.0.30319,而是在 GetSubKeyNames()方法给我的子键: {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E} .KB2151757 这没有任何显示名称。

And it should have the display name: Microsoft Visual C++ 2010 x64 Redistributable - 10.0.30319, but instead the GetSubKeyNames() method gives me the sub key : {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}.KB2151757 which doesn't have any display name.

为什么我不能得到确切的子键,我需要( {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E} ),我怎样才能得到它呢?

Why can't I get the exact sub key I need ({DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}) and how can I get it?

推荐答案

在64位操作系统的32位应用程序将在看 HKLM \\ SOFTWARE \\ Wow6432Node 默认节点。要读取密钥的64位版本,你需要指定 RegistryView

A 32-bit application on a 64-bit OS will be looking at the HKLM\Software\Wow6432Node node by default. To read the 64-bit version of the key, you'll need to specify the RegistryView:

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
}

要做到这一点的API添加在.NET 4.0中;如果你还在使用3.5,你需要使用的P / Invoke访问的64位密钥:
<一href=\"http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/\">http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/

The API to do this was added in .NET 4.0; if you're still using 3.5, you'll need to use P/Invoke to access the 64-bit keys: http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/

这篇关于OpenSubKey()的注册表项,我可以在REGEDIT.EXE看到返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆