如果程序无法正确卸载,我正在尝试删除多个注册表项。
我正在使用Any CPU编译程序,并在Windows 10 Pro(64位)上运行该程序。
我收到以下异常:
System.IO.IOException: No more data is available.
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.InternalGetSubKeyNames()
at Microsoft.Win32.RegistryKey.GetSubKeyNames()
at ...
当我运行以下代码时:
string[] items_list = new[]
{
"string1",
"string2",
"string3"
// ...
};
foreach (string subKeyName in Registry.ClassesRoot.GetSubKeyNames())
{
if (items_list.Any(item => subKeyName.StartsWith(item)))
{
DeleteSubKeyTree(Registry.ClassesRoot, subKeyName);
}
}
void DeleteSubKeyTree(RegistryKey regKey, string subKey)
{
try
{
regKey.DeleteSubKeyTree(subKey);
WriteToLog($@"Deleting sub key {subKey} from {regKey.Name}.");
}
catch (Exception ex)
{
WriteToLog(ex.Message);
}
}