Old 28th September 2007, 11:57   #1
RobertStrong
Junior Member
 
Join Date: Jan 2006
Posts: 22
Set Vista default app

I needed a simple plugin for setting an app as default for its registered handlers on Vista so I created a wiki page for it in case it comes in handy for anyone else.

SetVistaDefaultApp_plug-in

http://nsis.sourceforge.net/SetVistaDefaultApp_plug-in
RobertStrong is offline   Reply With Quote
Old 30th September 2007, 14:29   #2
RobertStrong
Junior Member
 
Join Date: Jan 2006
Posts: 22
The plugin has been updated to support all of the methods available with IApplicationAssociationRegistration

Application Association Registration plug-in

http://nsis.sourceforge.net/Application_Association_Registration_plug-in
RobertStrong is offline   Reply With Quote
Old 1st October 2007, 07:07   #3
Backland
Senior Member
 
Join Date: Sep 2006
Posts: 150
Thanks for sharing!
Backland is offline   Reply With Quote
Old 12th September 2019, 11:56   #4
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 535
Send a message via ICQ to Pawel
Can anyone confirm, that the NSIS plugin (Application Association Registration) fails in latest Windows 10 (18362.356)?
Pawel is offline   Reply With Quote
Old 12th September 2019, 12:43   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,169
Fails how? It should not crash but Windows 10 does not allow apps to change the default, only the user can set default apps.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 12th September 2019, 22:02   #6
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 535
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
Old 13th September 2019, 00:03   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,169
MSDN is very clear.

Quote:
Note As of Windows 8, the only functionality of this interface that is supported is QueryCurrentDefault.
And regarding default apps:

Quote:
This topic does not apply for Windows 10. The way that default file associations work changed in Windows 10. For more information, see the section on Changes to how Windows 10 handles default apps in this post.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th September 2019, 09:12   #8
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 535
Send a message via ICQ to Pawel
Yes, you are right. It should not work long time ago. But it was working on Windows 10.
Pawel is offline   Reply With Quote
Old 20th September 2019, 21:36   #9
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 535
Send a message via ICQ to Pawel
@Anders,

One more question.
I need to register Internet Browser (Vivaldi or Opera, whatever) as system default browser in Windows 10 with my installer (in old Windows it was easy, but not in Win10). To do it, I add all needed entries to system registry (to know what entries need to be added I installed the browser on clean virtual system and set it as default) and opens system Settings applet.

I do it using the following code:
ExecShell "open" "$SYSDIR\control.exe" "/name Microsoft.DefaultPrograms /page pageDefaultProgram"

Finally I refresh the shell using this command:
System::Call "Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)"


This opens this page -> http://www.meggamusic.co.uk/shup/156...efaultApps.png

But, I would like to open this window: http://www.meggamusic.co.uk/shup/156...hooseAnApp.png
Vivaldi can do this... I wonder how to do this programatically (in NSIS).


Do you maybe know the answer? Or anyone?
-Pawel
Pawel is offline   Reply With Quote
Old 24th September 2019, 13:58   #10
stass
Senior Member
 
Join Date: Nov 2012
Posts: 146
Pawel, maybe this will help:

https://web.archive.org/web/20190909...ns-per-user%2F

Last edited by Anders; 24th September 2019 at 19:26. Reason: Link workaround
stass is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
assoc, default, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump