@FreeStyler, you can do all of it in one line like this: Code: RegistryKey registry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false); Formatted (since nobody likes long lines): Code: RegistryKey registry = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32 ).OpenSubKey( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false ); Not that it really matters, but now we avoid writing @"SOFTWARE\Microsoft\Windows NT\CurrentVersion" twice! Disclaimer: Code has not been tested.
Does this already include the latest fix that solved issues with some keys? http://forums.mydigitallife.net/thr...-OEM-need-UEFI?p=510310&viewfull=1#post510310
First thanks for this very interesting post. I am working on using this code in an application but I have a strange problem: In the above snippet I am always getting null returned for digitalProductId ??? I can access most other values in the same key but impossible to read digitalProductId & digitalProductId4 I have been thinking about access right problem and therefore I have run Visual studio in administrator mode but in did not help? I can read the same digitalProductId from Office keys but I cant from Windows key ??? I am running on a windows 8 system. Any idea about what I am doing wrong? I am stuck and running out of ideas please help - thanks in advance
OK I foun d the problem For reference I put the solution here. What is happening is that I am using a 32 bits program on a 64 bit machine! 64-bit Windows mirrors 32-bit content in a way that is transparent to applications. 32-bit applications that use the registry access a mirrored hive inside HKLM\WOW6423Node, which is why I wasn't seeing the expected result when querying a key inside HKLM. Fortunately, .NET 4.0 includes an easy way that lets a 32-bit application see and use the 64-bit registry (and vice-versa). I just had to change the code as following: Code: RegistryKey RegistryBase = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); RegistryKey registry = RegistryBase.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\", false);