1!include UAC.nsh 2 3!ifndef INSTALL_MODE_PER_ALL_USERS 4 !include multiUserUi.nsh 5!endif 6 7!ifndef BUILD_UNINSTALLER 8 !ifndef HIDE_RUN_AFTER_FINISH 9 Function StartApp 10 ${if} ${isUpdated} 11 StrCpy $1 "--updated" 12 ${else} 13 StrCpy $1 "" 14 ${endif} 15 ${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" "$1" 16 FunctionEnd 17 18 !define MUI_FINISHPAGE_RUN 19 !define MUI_FINISHPAGE_RUN_FUNCTION "StartApp" 20 !endif 21 22 !ifmacrodef customWelcomePage 23 !insertmacro customWelcomePage 24 !endif 25 26 !ifmacrodef licensePage 27 !insertmacro skipPageIfUpdated 28 !insertmacro licensePage 29 !endif 30 31 !ifndef INSTALL_MODE_PER_ALL_USERS 32 !insertmacro PAGE_INSTALL_MODE 33 !endif 34 35 !ifdef allowToChangeInstallationDirectory 36 !include StrContains.nsh 37 38 !insertmacro skipPageIfUpdated 39 !insertmacro MUI_PAGE_DIRECTORY 40 41 # pageDirectory leave doesn't work (it seems because $INSTDIR is set after custom leave function) 42 # so, we use instfiles pre 43 !define MUI_PAGE_CUSTOMFUNCTION_PRE instFilesPre 44 45 # sanitize the MUI_PAGE_DIRECTORY result to make sure it has a application name sub-folder 46 Function instFilesPre 47 ${If} ${FileExists} "$INSTDIR\*" 48 ${StrContains} $0 "${APP_FILENAME}" $INSTDIR 49 ${If} $0 == "" 50 StrCpy $INSTDIR "$INSTDIR\${APP_FILENAME}" 51 ${endIf} 52 ${endIf} 53 FunctionEnd 54 !endif 55 56 # after change installation directory and before install start, you can show custom page here. 57 !ifmacrodef customPageAfterChangeDir 58 !insertmacro customPageAfterChangeDir 59 !endif 60 61 !insertmacro MUI_PAGE_INSTFILES 62 !insertmacro MUI_PAGE_FINISH 63!else 64 !insertmacro MUI_UNPAGE_WELCOME 65 !ifndef INSTALL_MODE_PER_ALL_USERS 66 !insertmacro PAGE_INSTALL_MODE 67 !endif 68 !insertmacro MUI_UNPAGE_INSTFILES 69 !insertmacro MUI_UNPAGE_FINISH 70!endif 71 72!macro initMultiUser 73 !ifdef INSTALL_MODE_PER_ALL_USERS 74 !insertmacro setInstallModePerAllUsers 75 !else 76 ${If} ${UAC_IsInnerInstance} 77 ${AndIfNot} ${UAC_IsAdmin} 78 # special return value for outer instance so it knows we did not have admin rights 79 SetErrorLevel 0x666666 80 Quit 81 ${endIf} 82 83 !ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED 84 !define MULTIUSER_INIT_TEXT_ADMINREQUIRED "$(^Caption) requires administrator privileges." 85 !endif 86 87 !ifndef MULTIUSER_INIT_TEXT_POWERREQUIRED 88 !define MULTIUSER_INIT_TEXT_POWERREQUIRED "$(^Caption) requires at least Power User privileges." 89 !endif 90 91 !ifndef MULTIUSER_INIT_TEXT_ALLUSERSNOTPOSSIBLE 92 !define MULTIUSER_INIT_TEXT_ALLUSERSNOTPOSSIBLE "Your user account does not have sufficient privileges to install $(^Name) for all users of this computer." 93 !endif 94 95 # checks registry for previous installation path (both for upgrading, reinstall, or uninstall) 96 StrCpy $hasPerMachineInstallation "0" 97 StrCpy $hasPerUserInstallation "0" 98 99 # set installation mode to setting from a previous installation 100 ReadRegStr $perMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation 101 ${if} $perMachineInstallationFolder != "" 102 StrCpy $hasPerMachineInstallation "1" 103 ${endif} 104 105 ReadRegStr $perUserInstallationFolder HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation 106 ${if} $perUserInstallationFolder != "" 107 StrCpy $hasPerUserInstallation "1" 108 ${endif} 109 110 ${GetParameters} $R0 111 ${GetOptions} $R0 "/allusers" $R1 112 ${IfNot} ${Errors} 113 StrCpy $hasPerMachineInstallation "1" 114 StrCpy $hasPerUserInstallation "0" 115 ${EndIf} 116 117 ${GetOptions} $R0 "/currentuser" $R1 118 ${IfNot} ${Errors} 119 StrCpy $hasPerMachineInstallation "0" 120 StrCpy $hasPerUserInstallation "1" 121 ${EndIf} 122 123 ${if} $hasPerUserInstallation == "1" 124 ${andif} $hasPerMachineInstallation == "0" 125 !insertmacro setInstallModePerUser 126 ${elseif} $hasPerUserInstallation == "0" 127 ${andif} $hasPerMachineInstallation == "1" 128 !insertmacro setInstallModePerAllUsers 129 ${else} 130 # if there is no installation, or there is both per-user and per-machine 131 !ifdef INSTALL_MODE_PER_ALL_USERS 132 !insertmacro setInstallModePerAllUsers 133 !else 134 !insertmacro setInstallModePerUser 135 !endif 136 ${endif} 137 !endif 138!macroend 139