Win installer with/without admin rights

10.3.x-maintenance
Miguel Angel Mulero Martinez 2018-01-12 15:05:31 +01:00
parent e30e546244
commit cc5f2cba56
1 changed files with 61 additions and 16 deletions

View File

@ -26,16 +26,12 @@ BrandingText "${COMPANY_NAME}"
!define MUI_ICON ".\bf_installer_icon.ico" !define MUI_ICON ".\bf_installer_icon.ico"
!define MUI_UNICON ".\bf_uninstaller_icon.ico" !define MUI_UNICON ".\bf_uninstaller_icon.ico"
# Request rights user level
RequestExecutionLevel highest
# define the resulting installer's name: # define the resulting installer's name:
OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}" OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}"
# set the default installation directory
!if ${PLATFORM} == 'win64'
InstallDir "$PROGRAMFILES64\${GROUP_NAME}\${FOLDER_NAME}\"
!else
InstallDir "$PROGRAMFILES\${GROUP_NAME}\${FOLDER_NAME}\"
!endif
# app dialogs # app dialogs
!insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ${LICENSE} !insertmacro MUI_PAGE_LICENSE ${LICENSE}
@ -52,19 +48,62 @@ OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}"
!insertmacro MUI_LANGUAGE "Korean" !insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Spanish" !insertmacro MUI_LANGUAGE "Spanish"
# default install dir, readed from registry from latest installation Function .onInit
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "InstallLocation"
# Check if older version
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation"
${If} $R0 != ""
StrCpy $INSTDIR $R0
${Else}
# Check if older version without administrative rights
ReadRegStr $R1 HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation"
${If} $R1 != ""
StrCpy $INSTDIR $R1
${Else}
# New version, select default folder
UserInfo::GetAccountType
Pop $R2
${If} $R2 == "Admin"
# set the default installation directory
!if ${PLATFORM} == 'win64'
StrCpy $INSTDIR "$PROGRAMFILES64\${GROUP_NAME}\${FOLDER_NAME}\"
!else
StrCpy $INSTDIR "$PROGRAMFILES\${GROUP_NAME}\${FOLDER_NAME}\"
!endif
${Else}
StrCpy $INSTDIR "$DOCUMENTS\${GROUP_NAME}\${FOLDER_NAME}\"
${Endif}
${Endif}
${Endif}
FunctionEnd
# default section start # default section start
Section Section
# remove the older version # remove the older version, users with admin rights
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \ ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation" "InstallLocation"
${If} $R0 != "" ${If} $R3 != ""
# delete the installed files of the older version # delete the installed files of the older version
RMDir /r $R0 RMDir /r $R3
${Else}
# remove the older version, users without admin rights
ReadRegStr $R4 HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation"
${If} $R4 != ""
# delete the installed files of the older version
RMDir /r $R4
${EndIf}
${EndIf} ${EndIf}
# define the path to which the installer should install # define the path to which the installer should install
@ -82,7 +121,7 @@ Section
CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\${APP_NAME} (English).lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}" "--lang=en" CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\${APP_NAME} (English).lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}" "--lang=en"
CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\Uninstall ${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_UNINSTALLER}" CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\Uninstall ${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_UNINSTALLER}"
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}" CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}"
# include in add/remove programs # include in add/remove programs
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"Publisher" "${COMPANY_NAME}" "Publisher" "${COMPANY_NAME}"
@ -97,6 +136,10 @@ Section
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"DisplayVersion" "${VERSION}" "DisplayVersion" "${VERSION}"
# include for users without admin rights
WriteRegStr HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation" "$INSTDIR"
# estimate the size # estimate the size
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0 IntFmt $0 "0x%08X" $0
@ -119,8 +162,10 @@ Section "Uninstall"
RMDir "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}" RMDir "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}"
RMDir "$SMPROGRAMS\${GROUP_NAME}" RMDir "$SMPROGRAMS\${GROUP_NAME}"
Delete "$DESKTOP\${APP_NAME}.lnk" Delete "$DESKTOP\${APP_NAME}.lnk"
# remove from add/remove programs # remove from add/remove programs
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
DeleteRegKey HKCU "Software\${GROUP_NAME}\${APP_NAME}"
DeleteRegKey /ifempty HKCU "Software\${GROUP_NAME}"
SectionEnd SectionEnd