以下代码对我不起作用:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
例外:
System.UnauthorizedAccessException | "无法写入注册表项"
Kyl*_*ons 27
非管理员和非管理员管理员用户无权修改HKEY_LOCAL_MACHINE键.以管理员身份运行程序.
即使是管理员,我也不认为你可以在LocalMachine上创建新的密钥.确保你这样做
Registry.LocalMachine.CreateSubKey(@"SOFTWARE\YourCompanyName\SomeNewKey");
Run Code Online (Sandbox Code Playgroud)
并不是
Registry.LocalMachine.CreateSubKey("SomeNewKey");
Run Code Online (Sandbox Code Playgroud)
下面的代码在注册表中创建密钥.
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Wow6432Node\\Names");
key.SetValue("Name", "Isabella");
key.Close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66004 次 |
| 最近记录: |