Viraj Ariyasinghe
Viraj Ariyasinghe

Reputation: 1

Nsis Scripting to recognize previous installation directory

I am trying to recognized the previous installation directory in nsis scripting language using registry.

I found a entry for uninstollation in this registry

HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PaperTrlQBDConnector" "UninstallString"

but the registry value is \xxx\xxxx\PaperTrlQBDConnector\unistall.exe

i want to extract the path without uninstall.exe to a variable.

Function PreDirCheck

         # discover if QBD Connector is already installed
         ClearErrors
         
         SetRegView 64

         ClearErrors
         ;ReadRegStr $previous_install_dir HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PaperTrlQBDConnector" "PreDir"
         ;${if} $previous_install_dir == 0
         ReadRegStr $previous_install_dir HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PaperTrlQBDConnector" "UninstallString"
         ;${Endif}
         
         
         IfErrors done
         ;sectionsetflags ${sec1} 0
         SetAutoClose false
         strcpy $INSTDIR $previous_install_dir
         MessageBox MB_ICONQUESTION|MB_YesNO|MB_DEFBUTTON2 "Detected previous version in Directory $previous_install_dir $\n Click Yes To update in the existing directory $\n Click No to completely remove PaperTrl SyncManager and install to a new location?" IDYes lbl_abort IDNo lbl_un

         lbl_abort:
         sectionsetflags ${sec2} 0
         Abort ;skip page
         

         lbl_un:
         !insertmacro UninstallExisting
         sectionsetflags ${sec2} 1

    done:
         SetAutoClose false
        ;!insertmacro MUI_PAGE_DIRECTORY
         sectionsetflags ${sec2} 1

FunctionEnd

i tried this code but it gives the variable value with the unistall.exe for the path

Upvotes: 0

Views: 65

Answers (1)

Anders
Anders

Reputation: 101569

InstallDirRegKey knows how to remove the .exe if you point it to your UninstallString value. Controlling its reg-view however is not possible.

You can also remove the last path component yourself:

!include "FileFunc.nsh"

Function .onInit
ReadRegStr $0 HK.. ...
${GetParent} "$0" $1
MessageBox MB_OK $1
FunctionEnd

Upvotes: 0

Related Questions