這不是爲我工作: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