public static Type ResolveClsidToType(Guid clsid) { string name = @"software\classes\clsid\{" + clsid.ToString() + @"}\InprocServer32"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(name, false)) { if (key != null) { using (RegistryKey key2 = key.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string str2 = null; if (key2 == null) { name = null; foreach (string str3 in key.GetSubKeyNames()) { name = str3; if (!string.IsNullOrEmpty(name)) { using (RegistryKey key3 = key.OpenSubKey(name)) { str2 = (string)key3.GetValue("Assembly"); if (!string.IsNullOrEmpty(str2)) { break; } } } } } else { str2 = (string)key2.GetValue("Assembly"); } if (!string.IsNullOrEmpty(str2)) { foreach (Type type in Assembly.Load(str2).GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } } return(null); } } } using (RegistryHandle handle = RegistryHandle.GetBitnessHKCR(IntPtr.Size != 8)) { if (handle != null) { using (RegistryHandle handle2 = handle.OpenSubKey(@"CLSID\{" + clsid.ToString() + @"}\InprocServer32")) { using (RegistryHandle handle3 = handle2.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string stringValue = null; if (handle3 == null) { name = null; foreach (string str in handle2.GetSubKeyNames()) { if (!string.IsNullOrEmpty(str)) { using (RegistryHandle handle4 = handle2.OpenSubKey(str)) { stringValue = handle4.GetStringValue("Assembly"); if (!string.IsNullOrEmpty(stringValue)) { break; } } } } } else { stringValue = handle3.GetStringValue("Assembly"); } if (!string.IsNullOrEmpty(stringValue)) { foreach (Type type2 in Assembly.Load(stringValue).GetTypes()) { if (type2.IsClass && (type2.GUID == clsid)) { return(type2); } } } return(null); } } } } return(null); }
public static Type ResolveClsidToType(Guid clsid) { string keyName = String.Concat("software\\classes\\clsid\\{", clsid.ToString(), "}\\InprocServer32"); using (RegistryKey clsidKey = Registry.LocalMachine.OpenSubKey(keyName, false)) { if (clsidKey != null) { using (RegistryKey assemblyKey = clsidKey.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string assemblyName = null; if (assemblyKey == null) { keyName = null; foreach (string subKeyName in clsidKey.GetSubKeyNames()) { keyName = subKeyName; if (String.IsNullOrEmpty(keyName)) { continue; } using (RegistryKey assemblyKeyAny = clsidKey.OpenSubKey(keyName)) { assemblyName = (string)assemblyKeyAny.GetValue("Assembly"); if (String.IsNullOrEmpty(assemblyName)) { continue; } else { break; } } } } else { assemblyName = (string)assemblyKey.GetValue("Assembly"); } if (String.IsNullOrEmpty(assemblyName)) { return(null); } Assembly asm = Assembly.Load(assemblyName); foreach (Type type in asm.GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } return(null); } } } // We failed to get the hive information from a native process hive lets go for the alternative bitness using (RegistryHandle hkcr = RegistryHandle.GetBitnessHKCR(IntPtr.Size == 8 ? false : true)) { if (hkcr != null) { using (RegistryHandle clsidKey = hkcr.OpenSubKey(String.Concat("CLSID\\{", clsid.ToString(), "}\\InprocServer32"))) { using (RegistryHandle assemblyKey = clsidKey.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string assemblyName = null; if (assemblyKey == null) { keyName = null; foreach (string subKeyName in clsidKey.GetSubKeyNames()) { keyName = subKeyName; if (String.IsNullOrEmpty(keyName)) { continue; } using (RegistryHandle assemblyKeyAny = clsidKey.OpenSubKey(keyName)) { assemblyName = (string)assemblyKeyAny.GetStringValue("Assembly"); if (String.IsNullOrEmpty(assemblyName)) { continue; } else { break; } } } } else { assemblyName = assemblyKey.GetStringValue("Assembly"); } if (String.IsNullOrEmpty(assemblyName)) { return(null); } Assembly asm = Assembly.Load(assemblyName); foreach (Type type in asm.GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } return(null); } } } } return(null); }