简体   繁体   English

注册表在Office 2007 64位和2010 32位中读取不同

[英]Registry read different in office 2007 64 bit and 2010 32 bit

I am building a COM addin using the office interops. 我正在使用Office Interop构建COM插件。 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. 奇怪的是,它在Excel 2007(64位)中完美地读取了许可证密钥,但是当我在Excel 2010(32位)中运行同一段代码时,从注册表中读取时,许可证密钥被填充为空字符串。 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. 与32位进程相比,64位进程读取注册表的不同部分。 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. 有关详细信息,请参见MSDN上注册表中的32位和64位应用程序数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM