src/Microsoft/Windows/ComponentObjectModel/_Library/ComponentRegistrationManager.cs
/// <summary>
/// Reads component registration information from the Windows Registry,
/// </summary>
/// <param name="clsid">The CLSID of the component</param>
/// <param name="scope">The <see cref="ComponentRegistrationScope"/> to read the component registration information from.</param>
/// <returns>A <see cref="ComponentRegistrationInformation"/> instance on success. Returns null, when no information is found.</returns>
/// <remarks>
/// The method returns any information it can find for a component in the windows registry.
/// The returned data needs to be validated by the caller prior for completness and accuracy.
/// </remarks>
Reads component registration information from the Windows Registry.
Reads component registration information from the Windows Registry .
public ComponentRegistrationInformation ReadByClsid( string clsid, ComponentRegistrationScope scope ) {
            if( string.IsNullOrEmpty( clsid ) ) {
                throw new ArgumentNullException( nameof( clsid ) );
            }
            RegistryHive hive = GetHiveForScopeOrThrow( scope );
            using( IRegistryKey hiveKey = _registry.OpenBaseKey( hive, RegistryView.Default ) ) {
                using( IRegistryKey clsidKey = hiveKey.OpenSubKey( s_CLSIDRegKeyName ) ) {
                    using( IRegistryKey componentKey = clsidKey.OpenSubKey( clsid ) ) {
                        if( null == componentKey ) {
                            return null;
                        }
                        string progId;
                        using( IRegistryKey progIdKey = componentKey.OpenSubKey( s_ProgIdKeyName ) ) {
                            progId = progIdKey?.GetString( "", "" ) ?? "";
                        }
                        ComponentServerType? serverType = null;
                        string[] serverKeyNames = componentKey.GetSubKeyNames();
                        if( serverKeyNames.Length == 0 ) {
                            return null;
                        }
                        foreach( string serverKeyName in serverKeyNames ) {
                            if( true == Enum.TryParse( serverKeyName, true, out ComponentServerType detectedServerType ) ) {
                                serverType = detectedServerType;
                                break;
                            }
                        }
                        if( !serverType.HasValue ) {
                            return null;
                        }
                        using( IRegistryKey serverKey = componentKey.OpenSubKey( Enum.GetName( typeof( ComponentServerType ), serverType ) ) ) {
                            string path = serverKey.GetString( "" );
                            _ = Enum.TryParse( serverKey.GetString( "ThreadingModel" ), true, out ComponentThreadingModel threadingModel );
                            if( path.EndsWith( ".comhost.dll" ) ) {
                                DotNetCoreComponentRegistrationInformation dotNetCore = new DotNetCoreComponentRegistrationInformation() {
                                    CLSID = Guid.Parse( clsid ),
                                    ComHost = path,
                                    Codebase = Utils.GetLibraryPath( path ),
                                    ProgId = progId,
                                    ServerType = serverType.Value,
                                    ThreadingModel = threadingModel,
                                };
                                return dotNetCore;
                            }
                            if( path.EndsWith( "mscoree.dll", StringComparison.OrdinalIgnoreCase ) ) {
                                DotNetFrameworkComponentRegistrationInformation dotNetFrameworkComponentInfo = new DotNetFrameworkComponentRegistrationInformation() {
                                    DotNetShimPath = path,
                                    CLSID = Guid.Parse( clsid ),
                                    ProgId = progId,
                                    ServerType = serverType.Value,
                                    ThreadingModel = threadingModel,
                                    SharedTypeInformation = GetValues( serverKey ),
                                };
                                string[] versionKeyNames = serverKey.GetSubKeyNames();
                                DotNetFrameworkComponentRegistrationTypeInformation versionedTypeInfo = null;
                                foreach( string versionKeyName in versionKeyNames ) {
                                    using( IRegistryKey versionedKey = serverKey.OpenSubKey( versionKeyName ) ) {
                                        versionedTypeInfo = GetValues( versionedKey );
                                        versionedTypeInfo.AssemblyVersion = versionKeyName;
                                        dotNetFrameworkComponentInfo.VersionedTypeInformation.Add( versionedTypeInfo );
                                    }
                                }
                                return dotNetFrameworkComponentInfo;
                            }
                            NativeComponentRegistrationInformation native = new NativeComponentRegistrationInformation() {
                                CLSID = Guid.Parse( clsid ),
                                Path = path,
                                ProgId = progId,
                                ServerType = serverType.Value,
                                ThreadingModel = threadingModel,
                            };
                            return native;
                        }
                    }
                }
            }
        }
public ComponentRegistrationInformation ReadByClsid ( string clsid , ComponentRegistrationScope scope ) { if ( string . IsNullOrEmpty ( clsid ) ) { throw new ArgumentNullException ( nameof ( clsid ) ) ; } RegistryHive hive = GetHiveForScopeOrThrow ( scope ) ; using ( IRegistryKey hiveKey = _registry . OpenBaseKey ( hive , RegistryView . Default ) ) { using ( IRegistryKey clsidKey = hiveKey . OpenSubKey ( s_CLSIDRegKeyName ) ) { using ( IRegistryKey componentKey = clsidKey . OpenSubKey ( clsid ) ) { if ( null == componentKey ) { return null ; } string progId ; using ( IRegistryKey progIdKey = componentKey . OpenSubKey ( s_ProgIdKeyName ) ) { progId = progIdKey ? . GetString ( " " , " " ) ?? " " ; } ComponentServerType ? serverType = null ; string [ ] serverKeyNames = componentKey . GetSubKeyNames ( ) ; if ( serverKeyNames . Length == 0 ) { return null ; } foreach ( string serverKeyName in serverKeyNames ) { if ( true == Enum . TryParse ( serverKeyName , true , out ComponentServerType detectedServerType ) ) { serverType = detectedServerType ; break ; } } if ( ! serverType . HasValue ) { return null ; } using ( IRegistryKey serverKey = componentKey . OpenSubKey ( Enum . GetName ( typeof ( ComponentServerType ) , serverType ) ) ) { string path = serverKey . GetString ( " " ) ; _ = Enum . TryParse ( serverKey . GetString ( " " ) , true , out ComponentThreadingModel threadingModel ) ; if ( path . EndsWith ( " " ) ) { DotNetCoreComponentRegistrationInformation dotNetCore = new DotNetCoreComponentRegistrationInformation ( ) { CLSID = Guid . Parse ( clsid ) , ComHost = path , Codebase = Utils . GetLibraryPath ( path ) , ProgId = progId , ServerType = serverType . Value , ThreadingModel = threadingModel , } ; return dotNetCore ; } if ( path . EndsWith ( " " , StringComparison . OrdinalIgnoreCase ) ) { DotNetFrameworkComponentRegistrationInformation dotNetFrameworkComponentInfo = new DotNetFrameworkComponentRegistrationInformation ( ) { DotNetShimPath = path , CLSID = Guid . Parse ( clsid ) , ProgId = progId , ServerType = serverType . Value , ThreadingModel = threadingModel , SharedTypeInformation = GetValues ( serverKey ) , } ; string [ ] versionKeyNames = serverKey . GetSubKeyNames ( ) ; DotNetFrameworkComponentRegistrationTypeInformation versionedTypeInfo = null ; foreach ( string versionKeyName in versionKeyNames ) { using ( IRegistryKey versionedKey = serverKey . OpenSubKey ( versionKeyName ) ) { versionedTypeInfo = GetValues ( versionedKey ) ; versionedTypeInfo . AssemblyVersion = versionKeyName ; dotNetFrameworkComponentInfo . VersionedTypeInformation . Add ( versionedTypeInfo ) ; } } return dotNetFrameworkComponentInfo ; } NativeComponentRegistrationInformation native = new NativeComponentRegistrationInformation ( ) { CLSID = Guid . Parse ( clsid ) , Path = path , ProgId = progId , ServerType = serverType . Value , ThreadingModel = threadingModel , } ; return native ; } } } } }
Reads component registration information from the Windows Registry,
Reads component registration information from the Windows Registry
// TODO: Ensure, that partial results are also passed back to caller. This is currently not the case for all cases. // Detect ServerType (InprocServer, InprocServer32, LocalServer, LocalServer32 // TODO: Improve ServerType detection // This detection logic has an issue, as it does not take into consideration, that there could be 2 in parallel for 16 and 32 bit // .NET Core COM component registration // TODO: Calculate component library path based on ComHost path // .NET Framework COM component registration // What, if default reg value is manipulated/corrupted, so that this reading logic would miss the .NET Framework specifics ? // Probably, this reading logic needs some revision. // Native component registration
A  instance on success. Returns null, when no information is found.
A instance on success . Returns null when no information is found .
clsid
string
The CLSID of the component
The CLSID of the component
scope
ComponentRegistrationScope
The  to read the component registration information from.
The to read the component registration information from .
remarks
The method returns any information it can find for a component in the windows registry.
The returned data needs to be validated by the caller prior for completness and accuracy.
The method returns any information it can find for a component in the windows registry . The returned data needs to be validated by the caller prior for completness and accuracy .