Added a file association example to install-per-user.nsi

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7167 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2020-04-13 19:16:10 +00:00
parent 821b4d6a18
commit b704d52400
6 changed files with 114 additions and 19 deletions

View file

@ -43,6 +43,9 @@ Function .onInit
${EndIf}
FunctionEnd
Function un.onInit
SetShellVarContext Current
FunctionEnd
Section "Program files (Required)"
SectionIn Ro
@ -50,29 +53,114 @@ Section "Program files (Required)"
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}"
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\MyApp.exe,0"
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"'
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoModify" 1
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1
File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install
;WriteRegStr HKCU "Software\Classes\.myfileext" "myfiletype"
;WriteRegStr HKCU "Software\Classes\myfiletype\shell\myapp\command" "" '"$InstDir\MyApp.exe" "%1"'
SectionEnd
Section "Start Menu shortcut"
CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe"
SectionEnd
/*
This Section registers a fictional .test-nullsoft file extension and the Nullsoft.Test ProgId.
Proprietary file types are encouraged (by Microsoft) to use long file extensions and ProgIds that include the company name.
When registering with "Open With" your executable should ideally have a somewhat unique name,
otherwise there could be a naming collision with a different application (with the same name) installed on the same machine.
REGISTER_DEFAULTPROGRAMS is not defined because proprietary file types do not typically use the Default Programs functionality.
If your application registers a standard file type such as .mp3 or .html or a protocol like HTTP it should register as a Default Program.
It should also register as a client (https://docs.microsoft.com/en-us/windows/win32/shell/reg-middleware-apps#common-registration-elements-for-all-client-types).
*/
!define ASSOC_EXT ".test-nullsoft"
!define ASSOC_PROGID "Nullsoft.Test"
!define ASSOC_VERB "MyApp"
!define ASSOC_APPEXE "MyApp.exe"
Section -ShellAssoc
# Register file type
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" "" "$InstDir\${ASSOC_APPEXE},0"
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "" "Nullsoft Test App" [Optional]
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "MUIVerb" "@$InstDir\${ASSOC_APPEXE},-42" ; WinXP+ [Optional] Localizable verb display name
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"'
WriteRegStr ShCtx "Software\Classes\${ASSOC_EXT}" "" "${ASSOC_PROGID}"
# Register "Open With" [Optional]
WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}" ; Win2000+ [Optional]
;WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" ; WinXP+ [Optional]
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\shell\open\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"'
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "FriendlyAppName" "Nullsoft Test App" ; [Optional]
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "ApplicationCompany" "Nullsoft" ; [Optional]
WriteRegNone ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\SupportedTypes" "${ASSOC_EXT}" ; [Optional] Only allow "Open With" with specific extension(s) on WinXP+
# Register "Default Programs" [Optional]
!ifdef REGISTER_DEFAULTPROGRAMS
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" "ApplicationDescription" "Shell association example test application"
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities\FileAssociations" "${ASSOC_EXT}" "${ASSOC_PROGID}"
WriteRegStr ShCtx "Software\RegisteredApplications" "Nullsoft Test App" "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities"
!endif
System::Call 'SHELL32::SHChangeNotify(i0x08000000, i0, p0, p0)' ; Notify the shell with SHCNE_ASSOCCHANGED
SectionEnd
Section -un.ShellAssoc
# Unregister file type
ClearErrors
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}\shell"
${IfNot} ${Errors}
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon"
${EndIf}
ReadRegStr $0 ShCtx "Software\Classes\${ASSOC_EXT}" ""
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}"
${IfNot} ${Errors}
${AndIf} $0 == "${ASSOC_PROGID}"
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}" ""
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}"
${EndIf}
# Unregister "Open With"
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}"
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList"
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}"
# Unregister "Default Programs"
!ifdef REGISTER_DEFAULTPROGRAMS
DeleteRegValue ShCtx "Software\RegisteredApplications" "Nullsoft Test App"
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}"
!endif
# Attempt to clean up junk left behind by the Windows shell
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Search\JumplistData" "$InstDir\${ASSOC_APPEXE}"
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.FriendlyAppName"
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.ApplicationCompany"
DeleteRegValue HKCU "Software\Microsoft\Windows\ShellNoRoam\MUICache" "$InstDir\${ASSOC_APPEXE}" ; WinXP
DeleteRegValue HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" "$InstDir\${ASSOC_APPEXE}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "${ASSOC_PROGID}_${ASSOC_EXT}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "Applications\${ASSOC_APPEXE}_${ASSOC_EXT}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithList"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}"
;DeleteRegKey HKCU "Software\Microsoft\Windows\Roaming\OpenWith\FileExts\${ASSOC_EXT}"
;DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\${ASSOC_EXT}"
System::Call 'SHELL32::SHChangeNotify(i0x08000000, i0, p0, p0)' ; Notify the shell with SHCNE_ASSOCCHANGED
SectionEnd
Section -Uninstall
Delete "$InstDir\MyApp.exe"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}"
;DeleteRegKey HKCU "Software\Classes\myfiletype\shell\myapp"
;DeleteRegKey /IfEmpty HKCU "Software\Classes\myfiletype\shell"
;DeleteRegKey /IfEmpty HKCU "Software\Classes\myfiletype"
Delete "$SMPrograms\${NAME}.lnk"
SectionEnd