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: InstallDat开发者_运维技巧e
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.
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. 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.
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. See C# Reading the registry: ProductID returns null in x86 targeted app. “Any CPU” works fine
精彩评论