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

homnis 发布于 2019-03-09 nsis 最后更新 2019-03-09 14:33 4 浏览

我有一个安装程序,可以在安装新版本之前卸载以前的版本。 但是,当最初的问题被问到时,它是这样做的。但卸载对话不。

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是孤立的。但是,如果你“手动”运行卸载程序,它似乎很好。除了试图让这个东西起作用之外,我没有改变任何逻辑。 谢谢。
已邀请:

edolor

赞同来自:

在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