尝试删除子项目树: 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?
更多推荐
发布评论