注册地在.NET:DeleteSubKeyTree说该子项不存在,但是,嘿,它确实! [英] Registry in .NET: DeleteSubKeyTree says the subkey does not exists, but hey, it does!
问题描述
试图删除一个子项树: HKEY_CURRENT_USER \软件\微软\的Windows \ CurrentVersion \ Explorer中\ FileExts \的.hdr
。 的.hdr
子项中有一个子项,没有任何价值。所以我用这个code:
Trying to delete a subkey tree: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.hdr
. .hdr
subkey has one subkey, no values. So I use this code:
RegistryKey FileExts = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts");
RegistryKey faulty = FileExts.OpenSubKey(".hdr");
Debug.Assert (faulty != null && faulty.SubKeyCount != 0);
faulty.Close();
FileExts.DeleteSubKeyTree(".hdr");
和我得到的的ArgumentException
与消息无法删除子树,因为该子项不存在的。
And I get the ArgumentException
with message "Cannot delete a subkey tree because the subkey does not exist."
跆拳道?我检查,并声称它确实存在?
WTF? I checked and asserted it did exist?
状态更新
寻求与过程监控,的.hdr的子项得到了交通运行code时,会拒绝
错误。我查了autorizations,但他们已经很好了?
Seeking with Process Monitor, the subkey of ".hdr" gets a ACCESS DENIED
error when running the code. I checked the autorizations, but they look fine?
推荐答案
找到了解决办法,这引起了其他另外一个问题... 的
指向访问被拒绝
误差进程监视器后,我只是想单独删除子项:
After pointing the ACCESS DENIED
error with Process Monitor, I just tried to delete subkeys individually:
RegistryKey hdr = FileExts.OpenSubKey(".hdr", true);
foreach (String key in hdr.GetSubKeyNames())
hdr.DeleteSubKey(key);
hdr.Close();
FileExts.DeleteSubKeyTree(".hdr");
它工作得很好,所以它不是一个权限问题!
It worked fine, so it's not a permission problem!
对于原因,我不明白,DeleteSubKeyTree需要一个空的树工作。
For a reason I don't understand, DeleteSubKeyTree needed an empty tree to work.
这是解释,任何人吗?
这篇关于注册地在.NET:DeleteSubKeyTree说该子项不存在,但是,嘿,它确实!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!