说明
一个驱动程序在注册表中留下了混乱(即使我从系统中将其卸载).如果我检查安全设置,它将不会在组或用户名"中显示任何内容.当我检查所有者时,它仅显示无法显示当前所有者.".当我想删除注册表项时,我必须:
One driver left a mess in the registry (even when I uninstalled it from the system). If I check the security setting it will not display anything in "Group or user names". And when I check the owner it shows only "Unable to display current owner.". When I want to delete the registry keys I have to:
取得所有权.
Take the ownership.
添加组.
删除密钥.
问题在于每个注册表都有几个子项,我必须在每个项上重复该过程.继承权限选项在注册表编辑器中不起作用.是的,我正在管理员模式下运行注册表编辑器.
The problem is that each registry has several sub keys and I have to repeat the process on each key. Inherit permission option will not work in Registry Editor. And yes, I am running Registry Editor in administrator mode.
问题
我想编写一个简单的C#代码,该代码将循环并删除所有键.我找到了一些代码示例,但就我而言,任何OpenSubKey调用都会因错误而失败: System.Security.SecurityException:不允许请求的注册表访问. 如果任何OpenSubKey函数调用失败,如何更改所有权?还有其他可用来声明所有权然后删除注册表项的命令吗?
I wanted to write a simple C# code that would loop and delete all keys. I have found some code samples, but in my case any OpenSubKey call would fail with error: System.Security.SecurityException: Requested registry access is not allowed. How can I change the ownership if any call of OpenSubKey function would fail? Is there any other command where I can claim the ownership and then delete the registry key?
感谢您的支持
推荐答案就像您知道以管理员身份运行注册表编辑器一样,以确保您具有修改/删除注册表项的适当特权,您需要对您的C#应用程序执行相同的操作.
Just as you knew to run the Registry Editor as an administrator in order to ensure that you would have the appropriate privileges to modify/delete registry keys, you need to do the same thing for your C# application.
由于您忘记了执行此操作,因此会抛出System.Security.SecurityException作为提醒.如异常消息所述,您无权修改/删除注册表项.
Because you forgot to do this, the System.Security.SecurityException is being thrown as a reminder. As the exception message says, you do not have the privileges to modify/delete the registry key(s).
要解决此问题,必须使用管理特权执行C#应用程序.您可以手动执行此操作,也可以向您的应用程序添加清单,这将导致该清单自动要求管理权限.
To solve the problem, you must execute your C# application with administrative privileges. You can either do this manually, or add a manifest to your application that will cause it to automatically demand administrative privileges.
更多推荐
删除顽固的注册表项
发布评论