以下代码对我不起作用:
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/