[Code Sample] GetSoftwareRoot without knowing 64 or 32bit mode

In the case where you explicitly need to read a value written by a 32 bit program in a 64 bit program, it’s OK to hard code it. Simply because there really is no other option.

I would of course abstract it out to a helper function. For example :

    private static RegistryKey GetSoftwareRoot()
        var path = IntPtr.Size == 8
                    ? @"Software\Wow6432Node"
                    : @"Software";
        return Registry.LocalMachine.OpenSubKey(path);


Leave a Reply