C#注册表权限

时间:2013-11-03 02:33:06

标签: c# .net permissions registry

我希望能够修改HKEY_CLASSES_ROOT的所有子键。

我有以下清单代码:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

我有以下汇编代码:

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CLASSES_ROOT")]

这有效:

 Registry.ClassesRoot.CreateSubKey("._test");

但是这失败了(除非以编程方式创建密钥):

 RegistryKey key = Registry.ClassesRoot.OpenSubKey("any_key");
 key.CreateSubKey("._test");

用户决定选择哪个键,因此我无法记下:

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CLASSES_ROOT/desired_subkey")]

因为在程序执行期间动态选择了desired_subkey。

所有想法?

1 个答案:

答案 0 :(得分:1)

Registry.OpenKey(string)只读取密钥。您需要使用overloads之一来为您提供写访问权限。