src/Microsoft/Windows/ComponentObjectModel/Shell/_Library/ShellExtensionManager.cs
/// <summary>
/// Disassociates a shell extension from a progId.
/// </summary>
/// <param name="progid">The progid.</param>
/// <param name="type">The type of the shell extension.</param>
/// <param name="name">The name of the shell extension.</param>
/// <param name="clsid">The clsid of the shell extension.</param>
/// <param name="scope">The registration scope.</param>
Disassociates a shell extension from a progId.
Disassociates a shell extension from a progId .
public void Disassociate( string progid, ShellExtensionHandlerType type, string name, string clsid, ComponentRegistrationScope scope ) {
            if( string.IsNullOrEmpty( progid ) ) {
                throw new ArgumentNullException( nameof( progid ) );
            }
            if( scope != ComponentRegistrationScope.User && scope != ComponentRegistrationScope.System ) {
                throw new ArgumentOutOfRangeException( nameof( scope ) );
            }
            if( null == type ) {
                throw new ArgumentNullException( nameof( type ) );
            }
            if( string.IsNullOrEmpty( name ) ) {
                throw new ArgumentNullException( nameof( name ) );
            }
            if( string.IsNullOrEmpty( clsid ) ) {
                throw new ArgumentNullException( nameof( clsid ) );
            }
            using( IRegistryKey classesKey = GetScopedClassesKey( scope, true ) ) {
                using( IRegistryKey progidKey = classesKey.OpenSubKey( progid, true ) ) {
                    if( null == progidKey ) {
                        return;
                    }
                    using( IRegistryKey shellexKey = progidKey.OpenSubKey( "shellex", true ) ) {
                        if( null == shellexKey ) {
                            return;
                        }
                        if( type.SupportsMultipleHandlers == false ) {
                            throw new NotImplementedException();
                        }
                        using( IRegistryKey handlerTypeKey = shellexKey.OpenSubKey( type.RegistrySubkey, true ) ) {
                            int subKeyCount = handlerTypeKey.SubKeyCount;
                            using( IRegistryKey handlerKey = handlerTypeKey.OpenSubKey( name, true ) ) {
                                if( null != handlerKey ) {
                                    string registeredClsid = handlerKey.GetString( "" );
                                    if( null == registeredClsid ) {
                                        throw new NotImplementedException();
                                    }
                                    if( !registeredClsid.Equals( clsid, StringComparison.OrdinalIgnoreCase ) ) {
                                        throw new NotImplementedException();
                                    }
                                    handlerKey.Close();
                                    handlerTypeKey.DeleteSubKeyTree( name, false );
                                }
                            }
                        }
                    }
                }
            }
        }
public void Disassociate ( string progid , ShellExtensionHandlerType type , string name , string clsid , ComponentRegistrationScope scope ) { if ( string . IsNullOrEmpty ( progid ) ) { throw new ArgumentNullException ( nameof ( progid ) ) ; } if ( scope != ComponentRegistrationScope . User && scope != ComponentRegistrationScope . System ) { throw new ArgumentOutOfRangeException ( nameof ( scope ) ) ; } if ( null == type ) { throw new ArgumentNullException ( nameof ( type ) ) ; } if ( string . IsNullOrEmpty ( name ) ) { throw new ArgumentNullException ( nameof ( name ) ) ; } if ( string . IsNullOrEmpty ( clsid ) ) { throw new ArgumentNullException ( nameof ( clsid ) ) ; } using ( IRegistryKey classesKey = GetScopedClassesKey ( scope , true ) ) { using ( IRegistryKey progidKey = classesKey . OpenSubKey ( progid , true ) ) { if ( null == progidKey ) { return ; } using ( IRegistryKey shellexKey = progidKey . OpenSubKey ( " " , true ) ) { if ( null == shellexKey ) { return ; } if ( type . SupportsMultipleHandlers == false ) { throw new NotImplementedException ( ) ; } using ( IRegistryKey handlerTypeKey = shellexKey . OpenSubKey ( type . RegistrySubkey , true ) ) { int subKeyCount = handlerTypeKey . SubKeyCount ; using ( IRegistryKey handlerKey = handlerTypeKey . OpenSubKey ( name , true ) ) { if ( null != handlerKey ) { string registeredClsid = handlerKey . GetString ( " " ) ; if ( null == registeredClsid ) { throw new NotImplementedException ( ) ; } if ( ! registeredClsid . Equals ( clsid , StringComparison . OrdinalIgnoreCase ) ) { throw new NotImplementedException ( ) ; } handlerKey . Close ( ) ; handlerTypeKey . DeleteSubKeyTree ( name , false ) ; } } } } } } }
Disassociates a shell extension from a progId.
Disassociates a shell extension from a progId .
// No progid key in registry. No more work to do. // 1. Try - Get handler subkey by name // Registered clsid is different from expected clsid
progid
string
None
type
ShellExtensionHandlerType
The type of the shell extension.
The type of the shell extension .
name
string
The name of the shell extension.
The name of the shell extension .
clsid
string
The clsid of the shell extension.
The clsid of the shell extension .
scope
ComponentRegistrationScope
The registration scope.
The registration scope .