无法写入注册表项,获得UnauthorizedAccessException [英] Cannot write to Registry Key, getting UnauthorizedAccessException

查看:956
本文介绍了无法写入注册表项,获得UnauthorizedAccessException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写在LOCAL_MACHINE注册表项

I have a windows service that attempt to write to a registry key in LOCAL_MACHINE

关键是作为一个Windows安装程序包的一部分创建的控制窗口服务和一个独立的控制窗口。

The key is created as part of a windows installer package the controls the windows service and a stand alone control window.

控制窗口可以读取和写入注册表项正常,但是我不能写,甚至当我充分的权限LOCAL SERVICE注册表项。

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.

这是在code抛出异常:

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());
}

有什么建议?

推荐答案

RegistryKey.OpenSubKey(字符串)不开的关键写作。尝试使用 OpenSubKey(字符串,布尔)超载指定你想要的关键是可写的。

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.

这篇关于无法写入注册表项,获得UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆