src/Microsoft/Windows/ComponentObjectModel/Shell/_Library/ShellExtensionManager.cs
/// <summary>
/// Associates a progId to a shell extension.
/// </summary>
/// <param name="progId">The progId.</param>
/// <param name="handlerType">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>
Associates a progId to a shell extension.
Associates a progId to a shell extension .
public void Associate( string progId, ShellExtensionHandlerType handlerType, 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 == handlerType ) {
                throw new ArgumentNullException( nameof( handlerType ) );
            }
            if( string.IsNullOrEmpty( name ) ) {
                throw new ArgumentNullException( nameof( name ) );
            }
            if( name.Length > 63 ) {
                throw new ArgumentException( "Parameter must not exceed a length of 63", nameof( name ) );
            }
            if( string.IsNullOrEmpty( clsid ) ) {
                throw new ArgumentNullException( nameof( clsid ) );
            }
            using( IRegistryKey classesKey = GetScopedClassesKey( scope, true ) ) {
                using( IRegistryKey progidKey = classesKey.CreateSubKey( progId, true ) ) {
                    using( IRegistryKey shellExKey = progidKey.CreateSubKey( "shellEx", true ) ) {
                        using( IRegistryKey handlerTypeKey = shellExKey.CreateSubKey( handlerType.RegistrySubkey, true ) ) {
                            if( handlerType.SupportsMultipleHandlers == false ) {
                                throw new NotImplementedException();
                            }
                            using( IRegistryKey handlerKey = handlerTypeKey.CreateSubKey( name, true ) ) {
                                handlerKey.SetValue( "", clsid, RegistryValueKind.String );
                            }
                        }
                    }
                }
            }
        }
public void Associate ( string progId , ShellExtensionHandlerType handlerType , 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 == handlerType ) { throw new ArgumentNullException ( nameof ( handlerType ) ) ; } if ( string . IsNullOrEmpty ( name ) ) { throw new ArgumentNullException ( nameof ( name ) ) ; } if ( name . Length > 63 ) { throw new ArgumentException ( " " , nameof ( name ) ) ; } if ( string . IsNullOrEmpty ( clsid ) ) { throw new ArgumentNullException ( nameof ( clsid ) ) ; } using ( IRegistryKey classesKey = GetScopedClassesKey ( scope , true ) ) { using ( IRegistryKey progidKey = classesKey . CreateSubKey ( progId , true ) ) { using ( IRegistryKey shellExKey = progidKey . CreateSubKey ( " " , true ) ) { using ( IRegistryKey handlerTypeKey = shellExKey . CreateSubKey ( handlerType . RegistrySubkey , true ) ) { if ( handlerType . SupportsMultipleHandlers == false ) { throw new NotImplementedException ( ) ; } using ( IRegistryKey handlerKey = handlerTypeKey . CreateSubKey ( name , true ) ) { handlerKey . SetValue ( " " , clsid , RegistryValueKind . String ) ; } } } } } }
Associates a progId to a shell extension.
Associates a progId to a shell extension .
// Length tested with Windows 10 x64 // TODO: Investigate, if registry sees the length in bytes or as count of chars. Modify length check based on research.
progId
string
None
handlerType
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 .