When I am installing, in the Destination Folder by default it is showing the path “C:\Program Files (x86)\DllTesting\” (It is as expected).
Then I tried to change the path to “C:\Program Files\AppTest”
But from the Browse once I selected the above path and clicked on “OK”, it is showing “C:\Program Files\AppTest\DllTesting” instead of “C:\Program Files\AppTest”
enter image description here When I remove “DllTesting” from the below path then it is showing the new path correctly without appending to the old path.
InstallDir $PROGRAMFILES\DllTesting
But I can’t remove “DllTesting” from the above path, because by default I should display the path “C:\Program Files (x86)\DllTesting\”
Below is my code snippet:
; DllTesting.nsi
;
;--------------------------------
!include LogicLib.nsh
Name "DllTesting"
OutFile "DllTesting.exe"
InstallDir $PROGRAMFILES\DllTesting
InstallDirRegKey HKLM "Software\NSIS_DllTesting" "Install_Dir"
RequestExecutionLevel admin
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
; The stuff to install
Section "DllTesting (required)"
SetOutPath $INSTDIR
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_DllTesting "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DllTesting" "DisplayName" "NSIS DllTesting"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DllTesting" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DllTesting" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DllTesting" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Please help me how to change the path from browse without appending to the previous path?
Read about InstallDir in documentation and you will find:
Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a
\
(which will require the entire parameter to be enclosed with quotes).
Try changing
InstallDir $PROGRAMFILES\DllTesting
to
InstallDir "$PROGRAMFILES\DllTesting\"