无法写入注册表项,出现 UnauthorizedAccessException
我有一个 Windows 服务尝试写入 LOCAL_MACHINE 中的注册表项
该注册表项是作为 Windows 安装程序包的一部分创建的,用于控制 Windows 服务和独立的控制窗口。
控制窗口可以很好地读取和写入注册表项,但是即使我授予本地服务完全权限,我也无法写入注册表项。
这是引发异常的代码:
private void updateLocalRegistryVersion(Double newVersion)
{
RegistryKey rk = Registry.LocalMachine;
RegistryKey sk = rk.OpenSubKey(@"Software\CompanyName\Monitoring\Values");
sk.SetValue("scriptversion", newVersion.ToString());
}
有什么建议吗?
I have a windows service that attempt to write to a registry key in LOCAL_MACHINE
The key is created as part of a windows installer package the controls the windows service and a stand alone control window.
The control window can read and write the registry key fine, however I cannot write to the registry key even when I give full permissions to LOCAL SERVICE.
This is the code that throws the exception:
private void updateLocalRegistryVersion(Double newVersion)
{
RegistryKey rk = Registry.LocalMachine;
RegistryKey sk = rk.OpenSubKey(@"Software\CompanyName\Monitoring\Values");
sk.SetValue("scriptversion", newVersion.ToString());
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RegistryKey.OpenSubKey(string)
不打开密钥进行写入。尝试使用OpenSubKey(string, bool)
重载来指定您希望密钥可写。RegistryKey.OpenSubKey(string)
does not open the key for writing. Try using theOpenSubKey(string, bool)
overload to specify that you want the key to be writable.