C# 在注册表本地计算机中创建值

标签 c# registry

以下代码对我不起作用:

public bool createRegistry()
{
    if (!registryExists())
    {
        Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\xelo\\");

        Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\xelo").SetValue("hostname", (string)hostname, Microsoft.Win32.RegistryValueKind.String);


        return true;
    }
    else
    {
        return updateRegistry();
    }
}

异常(exception):

System.UnauthorizedAccessException | "Cannot write to the registry key"

最佳答案

非管理员和未提升权限的管理员用户无权修改 HKEY_LOCAL_MACHINE 键。 “以管理员身份”运行程序。

关于C# 在注册表本地计算机中创建值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2723413/

相关文章:

c# - RavenDB:将文档属性转换为另一种类型

c# - 如何找到xml元素的最小值和最大值

powershell - 如何使用 Windows PowerShell 禁用 UAC?

java - 发现是否从 BAT 文件安装了 32 位或 64 位 Java

c++ - 如何循环加载所有用户的注册表配置单元

powershell - reg 卸载和新 key

c# - 将属性映射到集合自动映射器的属性

c# - 需要帮助通过类访问 DropDownList

c# - 为什么我需要 'dummy' 行代码才能加载PresentationFramework?

c# - 无法读取 Windows 8 中的注册表值