如何获得在C#注册表写入权限 [英] How to get registry write permissions in C#

查看:426
本文介绍了如何获得在C#注册表写入权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写在HKEY_CURRENT_USER\Software\appname windows的注册表,但是我不断收到权限错误,当我试图写的关键,我已经添加了以下到我的装配:

I'm trying to write to the windows registry at HKEY_CURRENT_USER\Software\appname however I keep getting a permissions error when I attempt to write to the key, I have added the following to my assembly:

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, Write = @"HKEY_CURRENT_USER\\Software")]

但是这并没有解决这个问题,有没有别的,我应该做些什么?

but this has not resolved the issue, is there something else that I should be doing?

推荐答案

RegistryPermissionAttribute 代码访问安全又称CAS ,这是检查权限系统的一部分你有.NET框架内的许可,这些权限由安全策略定义。 有4个安全策略的:

The RegistryPermissionAttribute is part of the Code Access Security aka CAS, this is a permission system which checks the permission you have inside of the .NET framework, these permissions are defined by the security policy. There are 4 security policies:


  • 企业 - 为家庭是Active Directory安装的一部分机的政策

  • 机 - 当前计算机策略

  • 用户 - 对于登录的用户策略

  • 的AppDomain - 。在执行应用程序域策略

  • Enterprise - policy for a family of machines that are part of an Active Directory installation.
  • Machine - policy for the current machine.
  • User - policy for the logged on user.
  • AppDomain - policy for the executing application domain.

第3在.net配置工具配置屏幕配置,最后是在运行时配置。

The first 3 are configured in the configuration screen in the .NET Configuration tool, and the last is configured at runtime.

我之所以解释这首先是因为RegistryPermissionAttribute只检查您的.net权限,它不检查在操作系统的权限。

The reason why I explain this first is because the RegistryPermissionAttribute only checks your .NET permissions, it does not check the Operating System permissions.

您可以使用系统.Security.AccessControl 检查操作系统权限,但要获得你可能需要要么提升或模拟的权限。

You could use the System.Security.AccessControl to check the operating system permissions, but to get the permissions you'll probably need to either elevate or impersonate.

这篇关于如何获得在C#注册表写入权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆