简体   繁体   English

列出注册表值的问题 C#

[英]Problems with listing registry values C#

when I try to list registry values it doesn't list all the values.当我尝试列出注册表值时,它没有列出所有值。 Like when I'm doing:就像我在做的时候:

RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");

foreach (string vName in regKey.GetValueNames())
{
     Console.WriteLine("Reg values: " + vName);
}

the answer I get is just these:我得到的答案就是这些:

Reg values: CurrentVersion
Reg values: CurrentBuild
Reg values: SoftwareType
Reg values: CurrentType
Reg values: InstallDate
Reg values: RegisteredOrganization
Reg values: RegisteredOwner
Reg values: SystemRoot
Reg values: InstallationType
Reg values: EditionID
Reg values: ProductName
Reg values: CurrentBuildNumber
Reg values: BuildLab
Reg values: BuildLabEx
Reg values: BuildGUID
Reg values: CSDBuildNumber
Reg values: PathName

I only get 17 lines when (if I look in the registry) 21 lines.当(如果我查看注册表)21 行时,我只得到 17 行。

What am I doing wrong?我究竟做错了什么? Greatful for every answer.对每一个答案都很棒。

This is because you're running your application as 32bit, and it is being redirected to the Wow64 node in the registry.这是因为您将应用程序作为 32 位运行,并且它被重定向到注册表中的 Wow64 节点。 You need to either change your application to x64/Anycpu or PInvoke the Windows Registry APIs manually and pass the KEY_WOW64_64KEY option for samDesired in RegOpenKeyEx. 您需要将应用程序更改为 x64/Anycpu 或 手动 PInvoke Windows 注册表 API ,并在 RegOpenKeyEx 中为 samDesired 传递 KEY_WOW64_64KEY 选项。

Edit: As posted by a commenter if you don't want to change to AnyCPU/x64 you can pass the KEY_WOW64_64KEY parameter to the .NET functions without resorting to the Windows API as well.编辑:正如评论者所发布的,如果您不想更改为 AnyCPU/x64,您可以将 KEY_WOW64_64KEY 参数传递给 .NET 函数,而无需使用 Windows ZDB974238714CA8A148A7CE10F。 See C# Reading the registry: ProductID returns null in x86 targeted app.请参阅C# 读取注册表:ProductID 在 x86 目标应用程序中返回 null。 “Any CPU” works fine “任何 CPU”都可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM