如何修复错误创建密钥注册表只读

时间:2015-11-28 08:26:40

标签: c# registrykey

我的代码在这里:

private void button1_Click(object sender, EventArgs e)
{
    RegistryKey Hklm = Registry.LocalMachine;
    RegistryKey HkSoftware = Hklm.OpenSubKey("Software");
    RegistryKey HkMicrosoft = HkSoftware.OpenSubKey("Microsoft");
    RegistryKey HkWindows = HkMicrosoft.OpenSubKey("Windows");
    RegistryKey HkMine = HkWindows.CreateSubKey("WindowsUpdate", RegistryKeyPermissionCheck.ReadWriteSubTree);
    HkMine.SetValue("NoAutoRebootWithLoggedOnUsers", 1);
}

Screenshot 1

在视觉工作室,它给了我错误:

1 个答案:

答案 0 :(得分:0)

不允许使用管理员权限(提升)运行的应用程序写入HKEY_LOCAL_MACHINE。多年来,微软一直在警告这一点。在Visual Studio中调试应用程序时,将使用Visual Studio在其下运行的相同用户权限启动应用程序。

解决方案是以管理员身份运行Visual Studio进行调试。

相关问题