本文介绍了使用 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# 删除注册表项
发布评论