无法写入注册表项,出现 UnauthorizedAccessException

发布于 2024-10-08 11:07:39 字数 470 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-10-15 11:07:39

RegistryKey.OpenSubKey(string) 不打开密钥进行写入。尝试使用 OpenSubKey(string, bool) 重载来指定您希望密钥可写。

RegistryKey.OpenSubKey(string) does not open the key for writing. Try using the OpenSubKey(string, bool) overload to specify that you want the key to be writable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文