Archive: Default Installation Path Changes on Reinstallation


Default Installation Path Changes on Reinstallation
Hi

I am using NSIS v2.29.

The initial install runs perfectly. If the installation program is run again on a machine with the program installed already, it adds "\bin" to the end of the default installation directory on the MUI_PAGE_DIRECTORY page.

Why is it appending the default installation directory at all? Also, why the bin directory? We have a bin subdirectory in the destination directory, but it's not even the first subdirectory.

When I try to install after I manually create the directory from within explorer, it works fine. This leads me to believe that it is a registry issue. Am I correct in thinking this? The registry code that I use (see below) I also use in other products of ours and I can happily reinstall those products perfectly.

Thank you
GDI Lord


.
.
.
;Include XML file handling
!include XML.nsh

; Include windows version check
!include "D:\Devbed\X\WinVer.nsh"
; Include IIS version check
!include "D:\Devbed\X\checkIISVersion.nsh"
; Include MSDE version check
!include "D:\Devbed\X\checkMSDE.nsh"
; Include .NET version check
!include "D:\Devbed\X\checkForDotNetVersion.nsh"
; Include virtual directory creation script
!include "D:\Devbed\X\CreateVirtualDirectory.nsh"


; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "eula.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\X"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\X"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "Afrikaans"
!insertmacro MUI_LANGUAGE "English"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "X.exe"
Section ; Hidden section to do the requirement checks:
; 1. IIS verison 5.0 or later
; 2. MSDE
; 3. .NET 1.1.4322
; 3. .NET 2.0.50727

; IIS 5.0 or later
StrCpy $0 5
StrCpy $1 0
push $0
push $1
Call CheckIISVersion

; MSDE
Call checkMSDE

; .NET 1.1.4322
StrCpy $0 "1.1.4322"
push $0
Call checkForDotNetVersion

; .NET 2.0.50727
StrCpy $0 "2.0.50727"
push $0
Call checkForDotNetVersion
SectionEnd

InstallDir "C:\Inetpub\wwwroot\X"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
.
.
.
Section -Post
WriteUninstaller "$INSTDIR\bin\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\X.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\bin\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bin\X.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallPath" "$INSTDIR"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"
SectionEnd

because of InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
you could change it to: InstallDirRegKey WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation"


Hi

Thanks. I have that statement in my -Post section.


Section -Post
WriteUninstaller "$INSTDIR\bin\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\X.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\bin\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bin\X.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallPath" "$INSTDIR"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"
SectionEnd

Will having WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"" in my main section as well lead to the creation on a duplicate when -Post is run, will the -Post simply overwite it or will an error be generated as the installer is trying to create a duplicate key in the registry?

Thank you

I get the install directory location from
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\X.exe
Problem was that X.exe resides in $\X\bin\

Now I am using
InstallDirRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallPath"
and it is working great.

Thank you anyway Anders.


yeah i forgot to strip off WriteRegStr from my example line, sorry


Just a note on uninstallation:
All you n00bs, learn from my experience and save yourself some hassle. The $\X\bin was messing me around on uninstallation as well. Note the first line in Section Uninstall.


Section Uninstall
ReadRegStr $INSTDIR ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallPath"
call un.UnReg
RMDir /r "$INSTDIR\back\"
.
.
.
RMDir /r "$INSTDIR\bin\"
Delete "$INSTDIR\*.*"

RMDir "$INSTDIR"
.
.
.
SectionEnd