View Single Post
Old 12th September 2019, 21:02   #6
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 527
Send a message via ICQ to Pawel
@Anders

I am using the following plugin in my installer code: https://nsis.sourceforge.io/mediawik...in&oldid=16469

This plugin allows me to set given app for given extension. It was working very nice.
Microsoft is trying to do everything to not allow to do this... I think, the plugin stopped working since last Windows 10 update...

When I call this (after adding all neccessary registry entries - see below in my macro):
PHP Code:
    AppAssocReg::SetAppAsDefault "${NAME}" ".${EXT}" "file" 
what means here for example:
PHP Code:
    AppAssocReg::SetAppAsDefault "AIMP" ".aac" "file" 
It should set AIMP default app for aac extension. As I said it was working - but today plugin fails...

Plugin help says:

PHP Code:
AppAssocReg::SetAppAsDefault app_name assoc_name type
Pop $Var
Sets an application 
as the default for the specified association name and type.

Returns:

'success' if the call was successful.
'method failed' if the call failed.
'method not available' if IApplicationAssociationRegistration is not available on the system
The problem is that now the plugin result is not any of above... just empty string... I was thinking maybe this is because Windows Defender, but probably Microsoft blocked this interface - IApplicationAssociationRegistration or something. Unfortunately I have no knowledge in this matter...

Here is the macro I use to register extensions for given application (in below exaple I use AIMP as app and aac as registered extension)

This is how I call macro:
(First parameter (217) is item number in config INI file, where are stored all apps and extensions)
PHP Code:
${MACRO_REGISTER_GIVEN_EXTENSION "217" "$INSTDIR\PLUGINS\Media\AIMP\AIMP.exe" "$INSTDIR\PLUGINS\Media\AIMP\AIMP.exe,0" "aac" "AIMP Media Player" "AIMP" "" 
PHP Code:
!define MACRO_REGISTER_GIVEN_EXTENSION "!insertmacro MACRO_REGISTER_GIVEN_EXTENSION"
!macro MACRO_REGISTER_GIVEN_EXTENSION NODE PATH ICONLIB EXT DESC NAME PARAM

    Push 
$1
    Push 
$2
    Push 
$3

    
${If} ${AtLeastWinVista} ; Windows 7

        ReadIniStr $R0 
"$PLUGINSDIR\Configs\INSTALLER_ASSOCIATIONS.ini" "Tree.Node${NODE}" "UserCheck" This config file contains apps with extensions 
        
Extension is registered if UserCheck 1(this file INSTALLER_ASSOCIATIONS.ini is populated on Custom Installer Page)
        
        ${If} 
$R0 == "1"

            
ReadRegStr "$0" "HKLM" "SOFTWARE\RegisteredApplications" "${NAME}"
            
${If} "$0" == ""
                
WriteRegStr "HKLM" "SOFTWARE\RegisteredApplications" "${NAME}" "SOFTWARE\Clients\Media\${NAME}\Capabilities"
                
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}" "" "${NAME}"
                
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}\Capabilities" "ApplicationName" "${NAME}"
                
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}\Capabilities" "ApplicationDescription" "${DESC}"
            
${EndIf}

            
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}\Capabilities\FileAssociations" ".${EXT}" "${NAME}.File.${EXT}"
            
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}\DefaultIcon" "" "${ICONLIB}"
            
WriteRegStr "HKLM" "SOFTWARE\Clients\Media\${NAME}\shell\open\command" "" '"${PATH}" ${PARAM} "%1"'

            
ReadRegStr "$0" "HKCR" ".${EXT}" ""
            
${If} "$0" != ""    key exists
                ReadRegStr 
"$1" "HKCR" ".${EXT}" "TCUP_Backup" check if we already backuped key
                
${If} "$1" == "" we did not
                    ReadRegStr 
"$2" "HKCR" ".${EXT}" "TCUP Extension" check if we created extension
                    
${If} "$2" == "" "TCUP Extension" value not exists
                        WriteRegStr 
"HKCR" ".${EXT}" "TCUP_Backup" "$0" backup old key value
                        WriteRegStr 
"HKCR" ".${EXT}" "" "${NAME}.File.${EXT}write new one
                    
${EndIf}
                    
WriteRegBin "HKCR" ".${EXT}\OpenWithProgIds" "${NAME}.File.${EXT}" ""
                
${EndIf}
            ${Else}
                
WriteRegStr "HKCR" ".${EXT}" "" "${NAME}.File.${EXT}Create own value
                WriteRegStr 
"HKCR" ".${EXT}" "TCUP Extension" "1"      set is as our
                WriteRegBin 
"HKCR" ".${EXT}\OpenWithProgIds" "${NAME}.File.${EXT}" ""
            
${EndIf}

            
WriteRegStr "HKCR" "${NAME}.File.${EXT}" "" ""
            
WriteRegStr "HKCR" "${NAME}.File.${EXT}\DefaultIcon" "" "${ICONLIB}"
            
WriteRegStr "HKCR" "${NAME}.File.${EXT}\shell" "" "Open"
            
WriteRegStr "HKCR" "${NAME}.File.${EXT}\shell\open\command" "" '"${PATH}" ${PARAM} "%1"'

            
AppAssocReg::SetAppAsDefault "${NAME}" ".${EXT}" "file"
            
Pop $1

            DetailPrint 
"${NAME} :: Extension registration: .${EXT}"
            
DetailPrint "Program: ${NAME}Program
            DetailPrint 
"Description: ${DESC}Desc
            DetailPrint 
"Parameter: ${PARAM}Param
            DetailPrint 
"Extension: .${EXT}Ext
            DetailPrint 
"Path: ${PATH}Path
            DetailPrint 
"Icon library: ${ICONLIB}Icon

            
${If} $== "success"
                
DetailPrint "Result: OK. Given extension has been correctly associated with program: '${NAME}'"
                
Save result
                WriteINIStr 
"$INSTALL_CONFIG_FILE" "${NAME} Extension" "${EXT}" "1"                
            
${else}
                
DetailPrint "Result: Error! Extension registration failed..."
                
Save result
                WriteINIStr 
"$INSTALL_CONFIG_FILE" "${NAME} Extension" "${EXT}" "0"
                
                
${If} $== "method failed"
                    
DetailPrint "Reason: Plugin Call Failed!"
                
${EndIf}
                ${If} $
== "method not available"
                    
DetailPrint "Reason: IApplicationAssociationRegistration is not available on the system!"
                
${EndIf}
            ${EndIf}

        ${Else}
            ; 
Save result
            WriteINIStr 
"$INSTALL_CONFIG_FILE" "${NAME} Extension" "${EXT}" "0"
        
${EndIf}

    ${EndIf}


    
Pop $0
    Pop 
$1
    Pop 
$2

!macroend 
The question is how to register given extension for given app to be default.
(Like in above example - make AIMP default app for aac extension - so, when user double click on aac file it will be opened in AIMP)

-Pawel
Pawel is offline   Reply With Quote