当卸载在onInit中时,NSIS不会中止安装

时间:2013-04-11 15:57:33

标签: nsis

我有一个安装程序,必须在安装新版本之前卸载以前的版本。

然而,当初始问题被问到时,它会这样做。但卸载对话框没有。

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  "${PRODUCT_NAME} is already installed. $\n$\nIf you have software older than 3.0,     please manually uninstall it with Windows before procedeing. $\n$\nClick `OK` to remove the \
  previous version or `Cancel` to cancel this upgrade." \
  IDOK uninst IDCANCEL giveup

; I am giving up
giveup:
Abort

;  Run the uninstaller
uninst:
 ClearErrors
 ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
 IfErrors no_remove_uninstaller
 no_remove_uninstaller:
 install:
 ; ..... snip

然后在这里

Function un.onInit
   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to     completely remove $(^Name) and all of its components?" IDYES NoAbort
  Abort
  NoAbort:
FunctionEnd

因此,当它是独立卸载时似乎没问题,但是当它在开始时卸载时,如果用户说没有/取消,安装程序仍然会在他们拒绝时继续。我想不出有什么原因。作为一个不良副作用,开始菜单上的程序文件图标是孤立的,uninst.exe是孤立的。但如果您“手动”运行卸载程序,它似乎没问题。除了试图让这个东西起作用之外,我没有改变任何逻辑。

感谢。

1 个答案:

答案 0 :(得分:2)

在ExecWait中引用路径然后检查退出代码非常重要:

Function .onInit
StrCpy $R0 "c:\old install" ; TODO: Somehow find the old install (in the registry? InstallDirRegKey?) and put its path in $R0
IfFileExists "$R0\*.*" 0 noOldInstall
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} is already installed. blahblah..." IDOK uninstOld
    Abort
    uninstOld:
    ExecWait '"$R0\uninstaller.exe" _?=$R0' $R1
    ; Exit codes are documented in Appendix D in the help file.
    StrCmp $R1 0 noOldInstall ; Success? If so we are done...
    Abort ; Uninstaller was canceled or failed, we cannot continue
noOldInstall:
FunctionEnd