My company has a 32-bit application that is frequently run in a 64-bit environment. There are some registry settings retrieved by this application that exist in the WoW6432Node in a 64-bit OS, but how can we make our application smart enough to look there without breaking backward compatibility with 32-bit operating systems or sacrificing future compatibility if our application is converted to 64-bit?
One option is to implement a solution like what’s described here. You can add logic to your application to determine whether the OS is 32 or 64 bit and access the appropriate key.
That’s great, but it’s a lot of work for a setting in my application that’s read once during initialization. Instead of going through all that trouble, I just implemented a simple retry algorithm to look in Wow6432Node if the key isn’t found in the default expected location.
var regKey = GetRegistryKey(@"SOFTWARE\MyCompany\Settings"); if (regKey == null) { regKey = GetRegistryKey(@"SOFTWARE\Wow6432Node\MyCompany\Settings"); if (regKey == null) { throw new InvalidOperationException( @"Unable to find registry key HKLM\SOFTWARE\MyCompany\Settings"); } } internal virtual RegistryKey GetRegistryKey(string path) { return Registry.LocalMachine.OpenSubKey( path, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey); }
It’s simple and it works–terrific!
This post and many other on your website are very interesting.
You should show your content to bigger audience. There is a big chance to go viral.
You need initial boost and visitors will flood your website in no
time. Simply search in google for:
Juuri13 viral effect