NSIS制作安装包,如何检测并卸载已有版本
将如下代码追加到NSIS脚本的尾部即可。
Var UNINSTALL_PROG
Function .onInit
ClearErrors
ReadRegStr $UNINSTALL_PROG ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
IfErrors done
MessageBox MB_YESNOCANCEL|MB_ICONQUESTION \
"检测到本机已经安装了 ${PRODUCT_NAME}。\
$\n$\n是否先卸载已安装的版本?" \
/SD IDYES \
IDYES uninstall \
IDNO done
Abort
uninstall:
CreateDirectory C:\WINDOWS\temp
CopyFiles $UNINSTALL_PROG C:\WINDOWS\temp\uninst.exe
ExecWait '"C:\WINDOWS\temp\uninst.exe" /S _?=C:\WINDOWS\temp' $0
DetailPrint "uninst.exe returned $0"
Delete "C:\WINDOWS\temp\uninst.exe"
done:
FunctionEnd