注册表不能写的问题

wy2ch 2005-04-13 03:28:16
RegistryKey hklm = Registry.LocalMachine;
RegistryKey hkSoftware = hklm.OpenSubKey("Software");
RegistryKey hkTest = hkSoftware.CreateSubKey("test");
hkTest.SetValue("test",5);
hkTest.Close();

未处理的“System.UnauthorizedAccessException”类型的异常出现在 mscorlib.dll 中。

其他信息: 无法写入到注册表项。
操作系统是 2000server
...全文
147 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinawn 2005-04-14
  • 打赏
  • 举报
回复
RegistryKey hkSoftware = hklm.OpenSubKey("Software",true);("表项",true);//此处true非常重要,如果没有将没有对注册表项下的子项的写权限
chinawn 2005-04-14
  • 打赏
  • 举报
回复
或者!
RegistryKey hklm = Registry.LocalMachine;
RegistryKey hkSoftware = hklm.OpenSubKey("Software",true);
RegistryKey hkTest = hkSoftware.CreateSubKey("test");
hkTest.SetValue("test","5");
hkTest.Close();
chinawn 2005-04-14
  • 打赏
  • 举报
回复
这样写看看!
RegistryKey hklm = Registry.LocalMachine;
RegistryKey hkSoftware = hklm.OpenSubKey("Software");
RegistryKey hkTest = hkSoftware.CreateSubKey("test");
hkTest.SetValue("test","5");
hkTest.Close();

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧