如何解决System.UnauthorizedAccessException:“无法写入注册表项”错误 [英] How to solve System.UnauthorizedAccessException : "Cannot write to the registry key" error

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

问题描述

<预类= "prettyprint">公共无效GetReqKey()
{
的RegistryKey OEMBg = Registry.LocalMachine.OpenSubKey(QUOT; SOFTWARE\\Microsoft\\Windows\\\ \\CurrentVersion\\Authentication\\LogonUI\\Background",TRUE);
if(OEMBg!= null)
{
OEMBg.SetValue(" OEMBackground",1,RegistryValueKind.DWord); - <此处报告错误。
}
}


我无法理解以下脚本有什么问题。我已经搜索了数千个博客,但仍然找不到它的答案。它总是抛出一个名为"System.UnauthorizedAccessException:'的异常,无法写入注册表项。" 。如果
,有人会帮助我,我会非常感激!。

解决方案

如果HKLM配置单元中的注册表项没有自定义安全性,则写访问权限要求该代码作为管理员以提升的权限运行。


public void GetReqKey()
        {
            RegistryKey OEMBg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\Background",true);
            if(OEMBg != null)
            {
                OEMBg.SetValue("OEMBackground",1,RegistryValueKind.DWord); --<Here the error is reported.
            }
        }

I cannot understand what is wrong with the following script. I have searched thousands of blogs but still cannot find the answer to it.It always throws an exception called "System.UnauthorizedAccessException: 'Cannot write to the registry key.'" .If someone would help me I would be very thankful!.

解决方案

Absent customization of security for a registry key in the HKLM hive, write access requires that code run with elevated privilege as an Administrator.


这篇关于如何解决System.UnauthorizedAccessException:“无法写入注册表项”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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