当安装卸载时,NSIS不会中止安装
问题描述:
我有一个安装程序,在安装新版本之前必须卸载以前的版本。当安装卸载时,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是孤立的。但是,如果你“手动”运行卸载程序,它似乎很好。除了试图让这个东西起作用之外,我没有改变任何逻辑。
谢谢。
答
它引用的路径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
我有这个已经定义: 定义PRODUCT_UNINST_KEY“软件\微软\的Windows \ CurrentVersion \卸载\ $ { PRODUCT_NAME}“ – 2013-04-11 20:33:47
对不起,我无法弄清楚如何在注释中解析新行,但是我应该使用readregstr来获取路径吗? – 2013-04-11 20:43:29
嗯,注册表本身具有默认密钥,它是具有可执行文件名称的完整路径,但没有其他程序在列表中执行的路径密钥。我可以不使用instdir或其他东西吗? – 2013-04-11 21:01:51