这不是为我工作:C#中注册本地计算机创造价值
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();
}
}
异常错误是无权做的事情。任何帮助,将apreaciated
Exeption:System.UnauthorizedAccessException | "Cannot write to the registry key"
对于工作复读上接受的解决方案
我是管理员,并以管理员身份运行给我相同的错误 – 2010-04-27 17:22:05
检查在regedit中的密钥的权限。 – Segfault 2010-04-27 17:28:37
尝试将true传递给OpenSubKey调用的第二个参数或使用CreateSubKey的返回值。 http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.opensubkey.aspx http://msdn.microsoft.com/en-us/library/ad51f2dx%28v=VS .100%29.aspx – 2010-04-27 17:32:26