I want to read the registry key \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName.
When I check the key in the registry editor, I'm getting the value "Window 10 Pro". However, when I'm reading the same key in my c# application, the result is "Window 10 Enterprise" Any ideas what the reason can be for this strange behaviour?
The OS is a Windows 10 64bit version, the application is targeted to .NET Framework 4.6.1, the platform for building in visual studio is 'Any CPU'.
The code snippet from my application:
registryKey = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
if (registryKey != null)
{
nameString = registryKey.GetValue("ProductName", "-Unknown-").ToString();
CodePudding user response:
I'd first check to make sure those two things actually ran on the same computer.
Otherwise, there is one thing that can do this. HKLM\Software has an entry called WOW6432Node
. The "WOW" here is for "Windows on Windows". It's used when older 32-bit processes access the registry to redirect the query into that section, similar to the Program Files
vs Program Files (x86)
folders. So a 32-bit process accessing here:
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
will instead read from here:
\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\ProductName
But again: for this particular key it would be very strange indeed for those two items to have different values.
CodePudding user response:
Some additional information: This question and answer explain how to force an application to read from \HKEY_LOCAL_MACHINE\SOFTWARE\Key and not from \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Key: How to avoid a wow6432node-redirection