I am building a COM addin using the office interops. I have code that reads a license key from the registry. The odd thing is that it reads the license key perfectly in Excel 2007 (64 bit) but then when I run the same piece of code in Excel 2010 (32 bit) the license key is populated as empty string when read from the registry. I am using this code to read the license key:
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Plugin\PluginSubFolder");
return (string)key.GetValue("License", "");
I know this issue is kind of vague and could result from a lot of things, but I’m not really sure where to start on debugging this.
Any ideas what could be causing this? I am happy to answer any additional questions about the code or the issue.
Thanks!
64 bit processes read a different part of the registry than 32 bit ones do. There is some OS redirection magic going on here.
Best solution is to add the key to both locations.
See 32-bit and 64-bit Application Data in the Registry on MSDN for details.