src/Microsoft/Windows/ComponentObjectModel/Shell/_Library/ShellExtensionManager.cs
/// <summary>
/// Tests for an association between a progid and a shell extension.
/// </summary>
/// <param name="classesKey">The classes registry key.</param>
/// <param name="progId">The progId</param>
/// <param name="shellHandlerTypeName">The name of the shell handler type.</param>
/// <param name="clsid">The clsid of the shell handler.</param>
/// <returns>true, if the progid is associated woth the shell extension. Otherwise, false.</returns>
Tests for an association between a progid and a shell extension.
Tests for an association between a progid and a shell extension .
static bool IsAssociated( IRegistryKey classesKey, string progId, string shellHandlerTypeName, string clsid ) {
            using( IRegistryKey progidKey = classesKey.OpenSubKey( progId ) ) {
                if( null == progidKey ) {
                    return false;
                }
                using( IRegistryKey shellHandlerTypeRegKey = progidKey.OpenSubKey( $@"shellex\{shellHandlerTypeName}" ) ) {
                    if( shellHandlerTypeRegKey == null ) {
                        return false;
                    }
                    foreach( string shellHandlerName in shellHandlerTypeRegKey.GetSubKeyNames() ) {
                        using( IRegistryKey shellHandlerKey = shellHandlerTypeRegKey.OpenSubKey( shellHandlerName ) ) {
                            string defaultHandlerValue = shellHandlerKey.GetString( "" );
                            if( defaultHandlerValue == clsid ) {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }
static bool IsAssociated ( IRegistryKey classesKey , string progId , string shellHandlerTypeName , string clsid ) { using ( IRegistryKey progidKey = classesKey . OpenSubKey ( progId ) ) { if ( null == progidKey ) { return false ; } using ( IRegistryKey shellHandlerTypeRegKey = progidKey . OpenSubKey ( $@" shellex\ { shellHandlerTypeName } " ) ) { if ( shellHandlerTypeRegKey == null ) { return false ; } foreach ( string shellHandlerName in shellHandlerTypeRegKey . GetSubKeyNames ( ) ) { using ( IRegistryKey shellHandlerKey = shellHandlerTypeRegKey . OpenSubKey ( shellHandlerName ) ) { string defaultHandlerValue = shellHandlerKey . GetString ( " " ) ; if ( defaultHandlerValue == clsid ) { return true ; } } } } } return false ; }
Tests for an association between a progid and a shell extension.
Tests for an association between a progid and a shell extension .
// Enumerate all registered shell handlers of a specific types and check for a given clsid
true, if the progid is associated woth the shell extension. Otherwise, false.
true if the progid is associated woth the shell extension . Otherwise false .
classesKey
IRegistryKey
The classes registry key.
The classes registry key .
progId
string
None
shellHandlerTypeName
string
The name of the shell handler type.
The name of the shell handler type .
clsid
string
The clsid of the shell handler.
The clsid of the shell handler .