Archive: INSTDIR remembers previous setting


INSTDIR remembers previous setting
Hi

I am having trouble with a couple of scripts and i am not sure whether this is a nsis bug or intended behaviour.

I have a zip file that the user extracts to some dir and then runs my nsis exe installer to just re-arrange a couple of directories and install a desktop and 2 start menu shortcuts (one for my app and one for an uninstaller).

I have a virtually identical 2nd script which does all the same stuff but for a slightly different flavour of my software.

So basically, in essence, i have installer_X and installer_Y and uninstaller_X and uninstaller_Y in the appropriate and completely separate X and Y dirs.

All seems to work fine if you only work with one app, either X or Y, doesn't matter, installs fine, uninstalls fine.

Now the problem comes if i install one app, lets say app X and then app Y then i attempt to uninstall X. The X uninstaller seems to use the INSTDIR variable from the last used installer on the machine, in this case Y!! The result is that uninstaller_X removes the files in the Y dir!

So to summarise, INSTDIR for the uninstaller seems to remember the value from the last used installer.


So my questions and plees for help are:

1) Can anyone repeat this?
2) Is it known or expected or intended or is it a bug i should report?
3) Is there a work-around i can try?

I suspect i have just misunderstood the proper INSTDIR usage
Thanks a lot in advance
Steve
:)


You are probably using the same InstallDirRegKey for both.

Stu


Here is my script - originally generated in Eclipse then edited by hand (i have added comments and censored some info for this post, hope that is ok):

# Auto-generated by EclipseNSIS Script Wizard
# 06-Aug-2007 13:53:41
# Then butchered by the fingers of xxx on 07-Aug-2007
# 20/09/07 xxx updated with a new shortcut icon

Name MyApp

# Defines
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 1_06 <---- This is the only thing that is different in the 2 scripts
!define COMPANY "MyCompany"
!define URL www.url.com

# Included files
!include Sections.nsh

# Reserved Files
ReserveFile "${NSISDIR}\Plugins\StartMenu.dll"

# Variables
Var StartMenuGroup

# Installer pages
Page custom StartMenuGroupSelect "" ": Start Menu Folder"
Page instfiles

# Installer attributes
OutFile InstallMyApp.exe
InstallDir $EXEDIR
CRCCheck on
XPStyle on
Icon "${NSISDIR}\Contrib\Graphics\Icons\classic-install.ico"
ShowInstDetails show
AutoCloseWindow true
VIProductVersion 1.0.0.0
VIAddVersionKey ProductName MyApp
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
VIAddVersionKey CompanyWebsite "${URL}"
VIAddVersionKey FileVersion ""
VIAddVersionKey FileDescription ""
VIAddVersionKey LegalCopyright ""
InstallDirRegKey HKLM "${REGKEY}" Path
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\classic-uninstall.ico"
ShowUninstDetails show

# Installer sections
!macro CREATE_SMGROUP_SHORTCUT NAME PATH
Push "${NAME}"
Push "${PATH}"
Call CreateSMGroupShortcut
!macroend

Section -Main SEC0000
SetOutPath $INSTDIR\MyApp
CreateShortcut "$DESKTOP\MyApp_${VERSION}.lnk" "$EXEDIR\MyApp\MyApp.jar" "" "$EXEDIR\MyApp\MyApp.ico"
CreateDirectory $EXEDIR\bin
CopyFiles /SILENT /FILESONLY $EXEDIR\MyApp\My_App.exe $EXEDIR\bin
CopyFiles /SILENT /FILESONLY $EXEDIR\MyApp\dlls\cygwin1.dll $EXEDIR\bin
CopyFiles /SILENT /FILESONLY $EXEDIR\MyApp\dlls\MyCompanyRunner.dll $EXEDIR\MyApp
CopyFiles /SILENT /FILESONLY $EXEDIR\MyApp\dlls\MyCompanyDLL.dll $EXEDIR\MyApp
CopyFiles /SILENT /FILESONLY $EXEDIR\MyApp\dlls\jspWin.dll $EXEDIR\MyApp
WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd

Section -post SEC0001
WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
WriteRegStr HKLM "${REGKEY}" StartMenuGroup $StartMenuGroup
SetOutPath $INSTDIR
WriteUninstaller $INSTDIR\UninstallMyApp_${VERSION}.exe
!insertmacro CREATE_SMGROUP_SHORTCUT "Uninstall $(^Name) ${VERSION}" $INSTDIR\UninstallMyApp_${VERSION}.exe
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\UninstallMyApp_${VERSION}.exe
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\UninstallMyApp_${VERSION}.exe
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
SetOutPath $INSTDIR\MyApp
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\MyApp_${VERSION}.lnk" "$EXEDIR\MyApp\MyApp.jar" "" "$EXEDIR\MyApp\MyApp.ico"
SectionEnd

# Macro for selecting uninstaller sections
!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
Push $R0
ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
StrCmp $R0 1 0 next${UNSECTION_ID}
!insertmacro SelectSection "${UNSECTION_ID}"
GoTo done${UNSECTION_ID}
next${UNSECTION_ID}:
!insertmacro UnselectSection "${UNSECTION_ID}"
done${UNSECTION_ID}:
Pop $R0
!macroend

# Uninstaller sections
!macro DELETE_SMGROUP_SHORTCUT NAME
Push "${NAME}"
Call un.DeleteSMGroupShortcut
!macroend

Section /o un.Main UNSEC0000
Delete /REBOOTOK $DESKTOP\MyApp_${VERSION}.lnk
DeleteRegValue HKLM "${REGKEY}\Components" Main
SectionEnd

Section un.post UNSEC0001
Delete $INSTDIR\bin\My_App.exe
Delete $INSTDIR\bin\cygwin1.dll
Delete $INSTDIR\MyApp\MyCompanyRunner.dll
Delete $INSTDIR\MyApp\MyCompanyDLL.dll
Delete $INSTDIR\MyApp\jspWin.dll
RMDir $INSTDIR\bin
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
!insertmacro DELETE_SMGROUP_SHORTCUT "Uninstall $(^Name) ${VERSION}"
!insertmacro DELETE_SMGROUP_SHORTCUT "MyApp_${VERSION}"
Delete /REBOOTOK $INSTDIR\UninstallMyApp_${VERSION}.exe
DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
DeleteRegValue HKLM "${REGKEY}" Path
DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
DeleteRegKey /IfEmpty HKLM "${REGKEY}"
RMDir $SMPROGRAMS\$StartMenuGroup
Push $R0
StrCpy $R0 $StartMenuGroup 1
StrCmp $R0 ">" no_smgroup
no_smgroup:
Pop $R0
SectionEnd

# Installer functions
Function StartMenuGroupSelect
Push $R1
StartMenu::Select /checknoshortcuts "Do not create shortcuts" /autoadd /text "Select the Start Menu folder in which to create the program's shortcuts:" /lastused $StartMenuGroup MyCompanyMyApp
Pop $R1
StrCmp $R1 success success
StrCmp $R1 cancel done
MessageBox MB_OK $R1
Goto done
success:
Pop $StartMenuGroup
done:
Pop $R1
FunctionEnd

Function .onInit
InitPluginsDir
FunctionEnd

Function CreateSMGroupShortcut
Exch $R0 ;PATH
Exch
Exch $R1 ;NAME
Push $R2
StrCpy $R2 $StartMenuGroup 1
StrCmp $R2 ">" no_smgroup
SetOutPath $SMPROGRAMS\$StartMenuGroup
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$R1.lnk" $R0
no_smgroup:
Pop $R2
Pop $R1
Pop $R0
FunctionEnd


# Uninstaller functions
Function un.onInit
ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
ReadRegStr $StartMenuGroup HKLM "${REGKEY}" StartMenuGroup
!insertmacro SELECT_UNSECTION Main ${UNSEC0000}
FunctionEnd

Function un.DeleteSMGroupShortcut
Exch $R1 ;NAME
Push $R2
StrCpy $R2 $StartMenuGroup 1
StrCmp $R2 ">" no_smgroup
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\$R1.lnk"
no_smgroup:
Pop $R2
Pop $R1
FunctionEnd


You are probably using the same InstallDirRegKey for both
ah, thanks for the quick response, i clearly don't understand that bit:

InstallDirRegKey HKLM "${REGKEY}" Path

Do i just make the HKLM bit different for both like:

InstallDirRegKey MyApp_${VERSION} "${REGKEY}" Path


thanks again

You need to change this line in both scripts:
Name MyApp

REGKEY is set to Software\$(^Name) which is Software\MyApp. Therefore as I expected, both your installers are saving their install directory path under the same registry key value.

And HKLM is HKEY_LOCAL_MACHINE so leave that.

Stu


fantastic, many thanks fella