How to use NSIS to add a program to the "Open With" menu

Viewed 234

I have a program that can open two types of files: .animera and .png. I'd like the program to be the default for .animera but not the default for .png. I have this for handling .animera files:

WriteRegStr HKCR '.animera' '' 'AnimeraSprite'
WriteRegStr HKCR 'AnimeraSprite' '' 'Animera Sprite'
WriteRegStr HKCR 'AnimeraSprite\shell' '' 'open'
WriteRegStr HKCR 'AnimeraSprite\shell\open\command' '' '"$INSTDIR\bin\Animera.exe" open "%1"'
WriteRegStr HKCR 'AnimeraSprite\shell\edit\command' '' '"$INSTDIR\bin\Animera.exe" open "%1"'
WriteRegStr HKCR 'AnimeraSprite\DefaultIcon' '' '$INSTDIR\bin\Animera.exe,1'

There seems to be a dozen ways of doing this but the above snippet works perfectly. Hovering shows that the file type is "Animera Sprite", the icon is shown and double clicking opens the program. I tried something similar for .png except that I don't want this program to be the default png viewer. I just want the user to have the option of using this program. Here's what I tried:

WriteRegStr HKCR '.png\OpenWithProgids' 'AnimeraPNG' ''
WriteRegStr HKCR 'AnimeraPNG\shell' '' 'open'
WriteRegStr HKCR 'AnimeraPNG\shell\open\command' '' '"$INSTDIR\bin\Animera.exe" open "%1"'

Right-clicking on a png file and then hovering "Open With" doesn't show the program in the list. So how do I accomplish this?

1 Answers

It looks like you did everything correctly but at some point (Windows 8?) Windows started requiring more information for applications to show up and MSDN was never updated.

You at least need to provide a company name and maybe a application name in the version info or in a undocumented registry key:

RequestExecutionLevel User
Name "Test"
OutFile "AnimeraPNG.exe"


!include "LogicLib.nsh"
!include "FileFunc.nsh"
Function .onInit
${GetParameters} $0
${If} $0 != ""
    MessageBox mb_ok "File:$0"
    Quit
${EndIf}
FunctionEnd

Section
WriteRegStr HKCU 'Software\Classes\.png\OpenWithProgids' 'AnimeraPNG' ''  ; WinXP+
WriteRegStr HKCU 'Software\Classes\AnimeraPNG\shell' '' 'open'
WriteRegStr HKCU 'Software\Classes\AnimeraPNG\shell\open\command' '' '"$exepath" "%1"'
SectionEnd


!if 1
VIProductVersion 1.2.3.4
VIAddVersionKey /LANG=0 "CompanyName" "AnimeraPNG fake company"
VIAddVersionKey /LANG=0 "ProductName" "AnimeraPNG product"
VIAddVersionKey /LANG=0 "FileDescription" "AnimeraPNG Application"
!else
Section
WriteRegStr HKCU 'Software\Classes\AnimeraPNG\Application' 'ApplicationName' 'AnimeraPNG'
WriteRegStr HKCU 'Software\Classes\AnimeraPNG\Application' 'ApplicationCompany' 'AnimeraPNG fake company'
;WriteRegStr HKCU 'Software\Classes\AnimeraPNG\Application' 'ApplicationIcon' '$exepath'
;WriteRegStr HKCU 'Software\Classes\AnimeraPNG\Application' 'ApplicationDescription' '...'
;WriteRegStr HKCU 'Software\Classes\AnimeraPNG\Application' 'AppUserModelId' '...'
SectionEnd
!endif

Or just add it as an extra verb:

WriteRegStr HKCU 'Software\Classes\SystemFileAssociations\.png\shell\AnimeraPNG\command' '' '"$exepath" "%1"' ; WinXP+
Related