使用 C# 删除注册表项

编程入门 行业动态 更新时间:2024-10-26 20:26:42
本文介绍了使用 C# 删除注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试删除这样的注册表项:

I am trying to delete a Registry key like this:

RegistryKey oRegistryKey = Registry.CurrentUser.OpenSubKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts", true); oRegistryKey.DeleteSubKeyTree(".");

但这给了我一个例外:

无法删除子键树,因为子键不存在

Cannot delete a subkey tree because the subkey does not exist

如果我将 DeleteSubKeyTree 更改为 DeleteSubKey,我会收到一个不同的异常:

If I change DeleteSubKeyTree to DeleteSubKey, I receive a different exception:

注册表项有子键,此方法不支持递归删除

Registry key has subkeys and recursive removes are not supported by this method

推荐答案

试试这个:

string str = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts"; string[] strSplit = strLocal.Split('\\'); using (RegistryKey oRegistryKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts", true)) { RegistryKey hdr = oRegistryKey.OpenSubKey(strSplit[strSplit.Length-2], true); foreach (String key in hdr.GetSubKeyNames()) hdr.DeleteSubKey(key); hdr.Close(); oRegistryKey.DeleteSubKeyTree(strSplit[strSplit.Length - 2]); }

还要检查:.NET 中的注册表:DeleteSubKeyTree 说该子项不存在,但是,它确实存在!

更多推荐

使用 C# 删除注册表项

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

发布评论

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

>www.elefans.com

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