public static void UnregisterComServer(Guid clsid)
{
// unregister class in categories.
string categoriesKey = String.Format(@"CLSID\{{{0}}}\Implemented Categories", clsid);
RegistryKey key = Registry.ClassesRoot.OpenSubKey(categoriesKey);
if (key != null)
{
try
{
foreach (string catid in key.GetSubKeyNames())
{
try
{
ConfigUtils.UnregisterClassInCategory(clsid, new Guid(catid.Substring(1, catid.Length-2)));
}
catch (Exception)
{
// ignore errors.
}
}
}
finally
{
key.Close();
}
}
string progidKey = String.Format(@"CLSID\{{{0}}}\ProgId", clsid);
// delete prog id.
key = Registry.ClassesRoot.OpenSubKey(progidKey);
if (key != null)
{
string progId = key.GetValue(null) as string;
key.Close();
if (!String.IsNullOrEmpty(progId))
{
try
{
Registry.ClassesRoot.DeleteSubKeyTree(progId);
}
catch (Exception)
{
// ignore errors.
}
}
}
// delete clsid.
try
{
Registry.ClassesRoot.DeleteSubKeyTree(String.Format(@"CLSID\{{{0}}}", clsid));
}
catch (Exception)
{
// ignore errors.
}
}