我如何要求用户卸载以前版本NSIS
-
23-08-2019 - |
解决方案
NSIS是一个伟大的Windows安装程序。下面是我如何使用NSIS卸载当前版本在安装相同的应用程序的新版本。将以下函数添加到您的NSIS脚本。
Function .onInit
Exec $INSTDIR\uninst.exe
FunctionEnd
您也可以在之前的“自动卸载旧退房在NSIS维基此链接安装新的”。
其他提示
另一种方法是使一个UninstallPrevious
隐藏区,并使其在安装所有其他部分之前运行。我也建议使卸载运行静默。
; The "" makes the section hidden.
Section "" SecUninstallPrevious
Call UninstallPrevious
SectionEnd
Function UninstallPrevious
; Check for uninstaller.
ReadRegStr $R0 HKLM "${HKLM_REG_KEY}" "InstallDir"
${If} $R0 == ""
Goto Done
${EndIf}
DetailPrint "Removing previous installation."
; Run the uninstaller silently.
ExecWait '"$R0\Uninstall.exe /S"'
Done:
FunctionEnd
这种方法的优点是,直到他们准备好安装新版本的用户将无法卸载旧版本。此外,他们甚至没有做出有关卸载旧版本的决定,它只是奇迹般地消失了。
当然,这取决于你的需求,你可能需要用户确认卸载,在这种情况下使用spinner_den的做法。
我重用得到期间写入的UninstallString
或QuietUninstallString
注册表项安装到稍后确定卸载程序命令。
一个耦合限定在顶部:
!define PROJECT_REG_UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROJECT_NAME}"
!define PROJECT_UNINSTALL_EXE "uninstall.exe"
在安装Section
:
WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\${PROJECT_UNINSTALL_EXE}" _?=$INSTDIR'
WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "QuietUninstallString" '"$INSTDIR\${PROJECT_UNINSTALL_EXE}" /S _?=$INSTDIR'
然后在你的.onInit
抢注册表项值(如果您的应用程序已经安装了这种方式会存在)并运行它:
${If} ${Silent}
ReadRegStr $R0 HKLM "${PROJECT_REG_UNINSTALL_KEY}" "QuietUninstallString"
${Else}
ReadRegStr $R0 HKLM "${PROJECT_REG_UNINSTALL_KEY}" "UninstallString"
${EndIf}
ExecWait "$R0"
不隶属于 StackOverflow