如何在c#registry中设置权限以完全控制

时间:2014-07-02 09:06:43

标签: c# forms regedit


我有一把名为" a"位于HKLM \ SOFTWARE
它的许可被设置为Deny ...... 我试图将它设置为完全控制:

     using (RegistryKey rk =
        Registry.LocalMachine.OpenSubKey(@"SOFTWARE\a"))
                {
                    string gname = Environment.UserDomainName + @"\" + Environment.UserName;
                    RegistrySecurity rs = new RegistrySecurity();
                    rs.AddAccessRule(new RegistryAccessRule(gname, RegistryRights.ReadKey, AccessControlType.Allow));
                    rk.SetAccessControl(rs);
                }

但它会在

处引发异常
    using (RegistryKey rk =
        Registry.LocalMachine.OpenSubKey(@"SOFTWARE\a"))

说"不允许请求注册表访问。" 任何想法?

1 个答案:

答案 0 :(得分:0)

RegistryKey.LocalMachine.OpenSubKey(@"SOFTWARE\a")没有打开写作的密钥。尝试使用RegistryKey.LocalMachine.OpenSubKey(@"SOFTWARE\a", true) overload指定您希望密钥可写。