简体   繁体   English

读取注册表项#1

[英]read registry key #1

I wrote a firefox extension and I want to check that it is loaded from a service developed in visual studio 2010 c#. 我写了一个firefox扩展,我想检查它是否是从Visual Studio 2010 c#中开发的服务加载的。 I have researched and tried numerous different methods to read a key and all I get is: "Registry read failed: System.NullReferenceException: Object reference not set to an instance of an object." 我已经研究并尝试了多种不同的方法来读取密钥,而我得到的只是:“注册表读取失败:System.NullReferenceException:对象引用未设置为对象的实例。” Here is one method I used: 这是我使用的一种方法:

RegistryKey rKey1 = Registry.CurrentUser;
RegistryKey rKey2 = rKey1.OpenSubKey("Software\\Mozilla\\Firefox\\Extensions");
string strKeyValue = rKey2.GetValue("thing@place.com").ToString();

Remember that your service runs under the account that is specified on the service configuration, so it's HKCU may be different than the current user that may be logged into the machine. 请记住,您的服务在服务配置上指定的帐户下运行,因此它的HKCU可能不同于可能登录到计算机的当前用户。 To test your code, try running the service under your user account instead of Local System, which is probably what it is running under now. 要测试您的代码,请尝试以您的用户帐户而不是本地系统(现在可能正在运行)运行服务。

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

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