madleeen
madleeen

Reputation: 107

Uninstall old version before installing new

I am new to NSIS, however I want to make checkup of existing installed older versions while installing the new one. I made this exactly like I found here - http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new But because I need to check were the old version is installed to make uninstallation correctly, I added InstallLocation registry value to the installation progress.

If I use ExecWait '$R0 _?=$INSTDIR' and the installation folder of the old version is the same as INSTDIR, everything works perfectly. But if I use ExecWait '$R0 _?=$R1' it gives me NSIS installer error, but I just can't find where is the problem, what have I done wrong?

Can someone help please? Thanks


Registry is added by this:


  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "InstallLocation" '"$INSTDIR"'

The code of function:


ReadRegStr $R0 HKLM \
 "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" \
 "UninstallString"

  StrCmp $R0 "" done

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
    "${AppName} is already installed. $\n$\nClick OK to remove the \
    previous version or Cancel to cancel the installation." \
IDOK uninst
Abort

;Run the uninstaller
uninst:
   ReadRegStr $R1 HKLM \
   "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" \
   "InstallLocation"

    ClearErrors
    HideWindow
    ClearErrors
    ExecWait '$R0 _?=$R1'
    BringToFront

done:
functionEnd

Upvotes: 1

Views: 3018

Answers (1)

Anders
Anders

Reputation: 101736

You are writing the InstallLocation path with quotes, don't do that or strip off the quotes in your code before executing the installer...

Upvotes: 2

Related Questions