Skip to content
⌘ NSIS Forum Archive

Last installation directory..

5 posts

ritesh#

Last installation directory..

Hello

By nsis script allows my app to be installed in \program files\etc.....

if a user has installed in some differnt directory and has an upgraded version of my software. how can i know where is the last installation so that by default i can show him the old directory?

need to add anything in the script...

Ritesh
kichik#
You simply write $INSTDIR to the registry and use InstallDirRegKey so the next installation will be able to read it. See Examples\example2.nsi for an example. All of the MUI examples in Examples\Modern UI example this too.
treehousetim#
Here is a quick macro I use for this...
it requires two entries in the .onInit and .onInstSuccess functions...


!Macro InstallLocationReg Root SubKey Key Default
Push $9
ReadRegStr $9 ${Root} ${SubKey} ${Key}
StrCmp $9 "" 0 +3
StrCpy $INSTDIR ${Default}
Goto +2
StrCpy $INSTDIR $9
Pop $9
!MacroEnd

Function .onInit
!insertmacro InstallLocationReg HKCU "SOFTWARE\Company\My\Software" "InstallDir" "$PROGRAMFILES\My\Software"
FunctionEnd

Function .onInstSuccess
WriteRegStr HKCU "SOFTWARE\Company\My\Software" "InstallDir" $INSTDIR
FunctionEnd

You also don't need to put an InstallDir "install/dir" in your script anywhere.

-Tim