如何解决System.UnauthorizedAccessException:“无法写入注册表项”错误 [英] How to solve System.UnauthorizedAccessException : "Cannot write to the registry key" error
问题描述
<预类= "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屋!