DeleteSubKey UnauthorizedAccessException [英] DeleteSubKey UnauthorizedAccessException
问题描述
我想写一个快速的应用程序来修改某些注册表项。当我通过注册表编辑器浏览,我可以修改,没有任何问题,删除键。
但是,当我尝试使用 RegistryKey.DeleteSubKey()
它抛出一个 UnauthorizedAccessException
。
有没有什么办法来获得特权做到这一点?另外,为什么会有一个问题,如果我的用户帐号显然访问进行更改?
编辑:
下面是一些code
的RegistryKey章;
尝试
{
章= Registry.CurrentUser.OpenSubKey(BaseKey);
reg.DeleteSubKey({+ Item.Guid.ToString()+});
}
抓住
{
返回false;
}
试试这个,而不是最初打开它的读/写,而不是只读:
的RegistryKey章;
尝试
{
章= Registry.CurrentUser.OpenSubKey(BaseKey,真正的); //< - 在这里!
reg.DeleteSubKey({+ Item.Guid.ToString()+});
}
抓住
{
返回false;
}
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.
But when I try to use RegistryKey.DeleteSubKey()
it throws an 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;
}
这篇关于DeleteSubKey UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!