Talk:Auto-uninstall old before installing new: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Reverted edits by 94.23.238.222 to last version by Anders)
 
(15 intermediate revisions by 7 users not shown)
Line 16: Line 16:
== Hans's comments ==
== Hans's comments ==


Please correct me if I'm wrong but as far as I know NSIS is not able to perform a "safe/consistent uninstallation" at all.
Consider the following Scenario:


Scenario:
<code>
<code>


Line 27: Line 26:
</code>
</code>


Since the installation has been canceled by the user I would expect that the system is left untouched - the old installation is still present.
Since the installation has been canceled by the user the old installation should still be present.


But if we call the uninstaller in the onInit callback then the old installation is gone.
But if you call the uninstaller in the onInit callback then the old installation is gone.
 
What NSIS is needs is another callback, e.g. an onPrepareFinished callback or something like that.


maybe it's possible to perform such on uninstallation in the onGUIEnd callback?
maybe it's possible to perform such on uninstallation in the onGUIEnd callback?
Line 42: Line 39:


   have one central function to perform the uninstallation (e.g. doMyUnInstall)  and then ...
   have one central function to perform the uninstallation (e.g. doMyUnInstall)  and then ...
     in the onGUIEnd callback call doMyUnInstall
     in the onGUIEnd callback use doMyUnInstall
     in the onInit callback check with the IsSilent function. If Yes call doMyUnInstall
     in the onInit callback check with the IsSilent function. If Yes then call doMyUnInstall


</code>
</code>
== Jeff Baylor's comments ==
I have been using this code snippet and really appreciate your posting it.  Recently I realized that it fails if the $INSTDIR is not the same as previous install directory.  I have modified it to be:
<highlight-nsis>
...
uninst:
  ReadRegStr $R1 HKLM \
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
  "InstallLocation"
  ClearErrors
  ExecWait '$R0 _?=$R1' ; Do not copy the uninstaller to $TEMP or $INSTDIR
...
</highlight-nsis>
== Sacha's comments ==
In my case I only needed to uninstall the previous version is case the user is installing it in the same folder as the previous one.
Hence I chose to silently uninstall with this line:
<highlight-nsis>
ExecWait '"$INSTDIR\uninst.exe" /S _?=$INSTDIR'
</highlight-nsis>
== Tossnet's comments ==
In my case, on a Windows 7 64bits
this code must be change
<highlight-nsis>
ReadRegStr $R0 HKLM \
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
  "UninstallString"
</highlight-nsis>
by this :
<highlight-nsis>
HKLM  \SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
  "UninstallString"
</highlight-nsis>
So i use another link from the regedit to look after a previus version.

Latest revision as of 20:25, 15 May 2013

Jeff's comments

In the second example, doesn't that assume that the old version's uninstaller is called 'uninst.exe' and that it resides in the same directory we're trying to install the new version into? The first example is using the value stored in the uninstall string key in the registry, which is a more robust way of doing it.

Also, in the first example, shouldn't you have a second parameter to iferrors?

 IfErrors uninstall_failed uninstall_succeeded
   uninstall_failed:
     ;You can either use Delete /REBOOTOK in the uninstaller or add some code
     ;here to remove the uninstaller. Use a registry key to check
     ;whether the user has chosen to uninstall. If you are using an uninstaller
     ;components page, make sure all sections are uninstalled.
   uninstall_succeeded:
     ;now you won't do the above deletion or whatever if the uninstall succeeded.

Hans's comments

Consider the following Scenario:

 (1) the installer GUI pops up
 (2) the user changes some settings
 (3) but finally the user decides to abort the installation

Since the installation has been canceled by the user the old installation should still be present.

But if you call the uninstaller in the onInit callback then the old installation is gone.

maybe it's possible to perform such on uninstallation in the onGUIEnd callback?

but for silent installation the onGUIEnd callback is not called at all.

Possible solution:

 have one central function to perform the uninstallation (e.g. doMyUnInstall)  and then ...
   in the onGUIEnd callback use doMyUnInstall
   in the onInit callback check with the IsSilent function. If Yes then call doMyUnInstall

Jeff Baylor's comments

I have been using this code snippet and really appreciate your posting it. Recently I realized that it fails if the $INSTDIR is not the same as previous install directory. I have modified it to be:

...
uninst:
  ReadRegStr $R1 HKLM \
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
  "InstallLocation"
 
  ClearErrors
  ExecWait '$R0 _?=$R1' ; Do not copy the uninstaller to $TEMP or $INSTDIR
...

Sacha's comments

In my case I only needed to uninstall the previous version is case the user is installing it in the same folder as the previous one.

Hence I chose to silently uninstall with this line:

ExecWait '"$INSTDIR\uninst.exe" /S _?=$INSTDIR'

Tossnet's comments

In my case, on a Windows 7 64bits this code must be change

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

by this :

HKLM  \SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
  "UninstallString"

So i use another link from the regedit to look after a previus version.