.NET中的注册表:DeleteSubKeyTree表示该子项不存在,但是嘿,确实如此!(Registry in .NET: DeleteSubKeyTree says the subkey does

编程入门 行业动态 更新时间:2024-10-14 16:27:27
.NET中的注册表:DeleteSubKeyTree表示该子项不存在,但是嘿,确实如此!(Registry in .NET: DeleteSubKeyTree says the subkey does not exists, but hey, it does!)

尝试删除子项目树: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.hdr 。 .hdr子键有一个子键,没有值。 所以我用这个代码:

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消息“无法删除子项树,因为该子项不存在。”

WTF? 我检查并断言它确实存在?

状态更新

在使用Process Monitor时,“.hdr”的子项在运行代码时会收到ACCESS DENIED错误。 我检查了自动调整,但它们看起来很好吗?

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");

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?

Status update

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?

最满意答案

找到了解决方案,引发了另一个问题......

在使用Process Monitor指出ACCESS DENIED错误后,我只是尝试单独删除子键:

RegistryKey hdr = FileExts.OpenSubKey(".hdr", true); foreach (String key in hdr.GetSubKeyNames()) hdr.DeleteSubKey(key); hdr.Close(); FileExts.DeleteSubKeyTree(".hdr");

它工作正常,所以这不是一个许可问题!

由于我不理解的原因,DeleteSubKeyTree需要一个空树来工作。

一个解释,有人吗?

Found a solution, which raises other another question...

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!

For a reason I don't understand, DeleteSubKeyTree needed an empty tree to work.

An explanation, anyone?

更多推荐

本文发布于:2023-08-07 01:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   注册表   确实   DeleteSubKeyTree   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!