简体   繁体   English

DeleteSubKey UnauthorizedAccessException

[英]DeleteSubKey UnauthorizedAccessException

I'm trying to write a quick app to modify some registry keys. 我正在尝试编写一个快速应用程序来修改一些注册表项。 When I'm browsing via RegEdit, I can modify and delete the keys with no problems. 当我通过RegEdit浏览时,我可以毫无问题地修改和删除密钥。

But when I try to use RegistryKey.DeleteSubKey() it throws an UnauthorizedAccessException . 但是当我尝试使用RegistryKey.DeleteSubKey()它会抛出一个UnauthorizedAccessException

Is there any way to gain the privileges to do this? 有没有办法获得这样做的特权? Also, why would there be a problem if my user account obviously has access to make the changes? 另外,如果我的用户帐户显然有权进行更改,为什么会出现问题呢?

Edit: 编辑:

Here's some code 这是一些代码

RegistryKey reg;

try
{
    reg = Registry.CurrentUser.OpenSubKey(BaseKey);
    reg.DeleteSubKey("{" + Item.Guid.ToString() + "}");
}
catch
{
    return false;
}

Try this instead, open it initially as read/write instead of read-only: 试试这个,最初打开它作为读/写而不是只读:

RegistryKey reg;

try
{
    reg = Registry.CurrentUser.OpenSubKey(BaseKey, true); //<--over here!
    reg.DeleteSubKey("{" + Item.Guid.ToString() + "}");
}
catch
{
    return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM