NSIS製作安裝包,如何檢測並解除安裝已有版本
阿新 • • 發佈:2019-01-04
將如下程式碼追加到NSIS指令碼的尾部即可。
Var UNINSTALL_PROG
Var OLD_VER
Var OLD_PATH
Function .onInit
ClearErrors
ReadRegStr $UNINSTALL_PROG ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
IfErrors done
ReadRegStr $OLD_VER ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "DisplayVersion"
MessageBox MB_YESNOCANCEL|MB_ICONQUESTION \
"檢測到本機已經安裝了 ${PRODUCT_NAME} $OLD_VER。\
$\n$\n是否先解除安裝已安裝的版本?" \
/SD IDYES \
IDYES uninstall \
IDNO done
Abort
uninstall:
StrCpy $OLD_PATH $UNINSTALL_PROG -10
ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0
DetailPrint "uninst.exe returned $0"
Delete "$UNINSTALL_PROG"
RMDir $OLD_PATH
done:
FunctionEnd