C#读取Windows自动更新注册表返回空值。

4
我有一个C#应用程序,尝试从以下路径读取"WindowsUpdate"子键:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update,但总是返回null。以下是代码示例:
Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion");
    {HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion}
        base {System.MarshalByRefObject}: {HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion}
        Handle: {Microsoft.Win32.SafeHandles.SafeRegistryHandle}
        Name: "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion"
        SubKeyCount: 52
        ValueCount: 11
        View: Default
    Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate");
    null
    Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update");
    null
    Registry.LocalMachine.OpenSubKey("Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate");
    null

请问您的Windows平台是x86还是x64?另外,您的应用程序平台是x86还是x64? - Rezoan
windows-server-2008-r2 - hupseb
仅适用于x64。 - hupseb
2
尝试从基于x64的应用程序中读取x64注册表,否则您将获得空响应。 - Rezoan
1
谢谢Rezoan!x64位应用程序解决了我的问题。 - christopher_h
@hupseb,你找到解决办法了吗?我在Windows更新后遇到了问题。 - Nayas Subramanian
1个回答

2
从上面的评论中可以看出您正在尝试读取x64注册表。因此,请尝试使用基于x64的应用程序来读取它。这应该可以解决您的问题。如果您正在使用基于x86的应用程序从基于x64的计算机中读取注册表,则会从以下位置读取:

HKEY_LOCAL_MACHINE\Software\Wow6432Node\

而不是从以下位置读取:

HKEY_LOCAL_MACHINE\Software

这样您就无法读取仅在x64注册表下可用的注册表键。


在 Windows 8.1 Enterprise (64 位) 上使用 C# .NET 4.5.2。仍然返回 WindowsUpdate 键的 null 值,因此其下没有任何内容。 - Bob Peterson
尝试在x64位平台下构建您的应用程序。 - Rezoan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接