我对 c# 相当陌生。我想实现一个接一个地删除多个注册表项,但是第一个键出现异常,之后代码停止删除其他键。我尝试了下面提到的代码,它适用于 if 块中的单个键
string[] keyArray = { @"Wow6432Node\CLSID",
@"Software\Microsoft\Windows\CurrentVersion\Ext\Settings",
@"Software\Microsoft\Windows\CurrentVersion\Ext\Stats",
@"SOFTWARE\Classes\Wow6432Node\CLSID",
@"SOFTWARE\Wow6432Node\Classes\CLSID",
@"Wow6432Node\Microsoft\Code Store Database\Distribution Units",
@"Wow6432Node\Microsoft\Internet Explorer\ActiveX Compatibility",
@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\ModuleUsage"
};
foreach (var key in keyArray)
{
try
{
RegistryKey myKey = Registry.ClassesRoot.OpenSubKey(key, true);
if (myKey != null)
{
/*Cisco Secure Desktop*/
myKey.DeleteSubKeyTree("{705EC6D4-B138-4079-A307-EF13E4889A82}");
myKey.DeleteSubKeyTree("{F8FC1530-0608-11DF-2008-0800200C9A66}");
myKey.DeleteSubKeyTree("{E34F52FE-7769-46CE-8F8B-5E8ABAD2E9FC}");
/*Cisco Hostscan*/
myKey.DeleteSubKeyTree("{F8FC1530-0608-11DF-2008-0800200C9A66}");
myKey.DeleteSubKeyTree("{E34F52FE-7769-46CE-8F8B-5E8ABAD2E9FC}");
/*Cisco AnyConnect Secure Mobility Client*/
myKey.DeleteSubKeyTree("{55963676-2F5E-4BAF-AC28-CF26AA587566}");
myKey.DeleteSubKeyTree("{CC679CB8-DC4B-458B-B817-D447B3B6AC31}");
}
else
Console.WriteLine(string.Format("could not open key: {0}", key));
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(
string.Format("action {0} failed with\n{1}", key, ex.Message));
}
}