NSIS检测已安装并卸载旧版本和静默安装.msu文件
2017-10-29 11:31
603 查看
NSIS检测已安装并卸载旧版本:
Function .onInit
!insertmacro TIP_WHEN_AMD64_INSTALLER_RUNAT_X86
;安装到所有用户下,current 表示安装到当前用户下, all 表示所有用户下。
SetShellVarContext all
ClearErrors
SetRegView 64
ReadRegStr $UNINSTALL_PROG ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
IfErrors done
ReadRegStr $OLD_VER ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "DisplayVersion"
SetRegView lastused
MessageBox MB_YESNOCANCEL|MB_ICONQUESTION \
"检测到本机已经安装了 ${PRODUCT_NAME} $OLD_VER。\
$\n$\n是否先卸载已安装的版本?" \
/SD IDYES \
IDYES uninstall \
IDNO done
Abort
uninstall:
StrCpy $OLD_PATH $UNINSTALL_PROG -11
ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0
DetailPrint "uninst.exe returned $0"
Delete "$UNINSTALL_PROG"
RMDir $OLD_PATH
done:
FunctionEnd
其中:
1. StrCpy $OLD_PATH $UNINSTALL_PROG -11 相当于获取安装路径:相当于下面两行代码 ("\uninst.exe"一共占11个字符 )
${GetParent} $UNINSTALL_PROG $R1
strcpy $OLD_PATH $R1
2. ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0 是执行相应的uninst.exe卸载文件。/S 是静默卸载。_?= 作用是将uninst.exe拷贝到临时文件夹( %temp%)之后,再在(_?=后面的)$OLD_PATH文件夹执行的。
可以参考Anders说的:
Running the uninstaller with _?= is never going to delete the uninstaller .exe.
When running the uninstaller without _?= what happens is:
uninst.exe is copied to %temp%\~un.exe
uninst.exe does Exec %temp%\~un.exe _?=instdir and quits
%temp%\~un.exe performs uninstall including deleting uninst.exe in $instdir
静默安装.msu文件
ExecWait 'wusa.exe "$INSTDIR\CamDrive\Windows6.1-KB2921916-x64.msu" /quiet /norestart' $0
DetailPrint "Windows6.1-KB2921916-x64.msu安装返回了 $0"
参考文章:http://blog.csdn.net/crazycoder8848/article/details/13703489
https://nsis-dev.github.io/NSIS-Forums/html/t-362421.html
Function .onInit
!insertmacro TIP_WHEN_AMD64_INSTALLER_RUNAT_X86
;安装到所有用户下,current 表示安装到当前用户下, all 表示所有用户下。
SetShellVarContext all
ClearErrors
SetRegView 64
ReadRegStr $UNINSTALL_PROG ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
IfErrors done
ReadRegStr $OLD_VER ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "DisplayVersion"
SetRegView lastused
MessageBox MB_YESNOCANCEL|MB_ICONQUESTION \
"检测到本机已经安装了 ${PRODUCT_NAME} $OLD_VER。\
$\n$\n是否先卸载已安装的版本?" \
/SD IDYES \
IDYES uninstall \
IDNO done
Abort
uninstall:
StrCpy $OLD_PATH $UNINSTALL_PROG -11
ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0
DetailPrint "uninst.exe returned $0"
Delete "$UNINSTALL_PROG"
RMDir $OLD_PATH
done:
FunctionEnd
其中:
1. StrCpy $OLD_PATH $UNINSTALL_PROG -11 相当于获取安装路径:相当于下面两行代码 ("\uninst.exe"一共占11个字符 )
${GetParent} $UNINSTALL_PROG $R1
strcpy $OLD_PATH $R1
2. ExecWait '"$UNINSTALL_PROG" /S _?=$OLD_PATH' $0 是执行相应的uninst.exe卸载文件。/S 是静默卸载。_?= 作用是将uninst.exe拷贝到临时文件夹( %temp%)之后,再在(_?=后面的)$OLD_PATH文件夹执行的。
可以参考Anders说的:
Running the uninstaller with _?= is never going to delete the uninstaller .exe.
When running the uninstaller without _?= what happens is:
uninst.exe is copied to %temp%\~un.exe
uninst.exe does Exec %temp%\~un.exe _?=instdir and quits
%temp%\~un.exe performs uninstall including deleting uninst.exe in $instdir
静默安装.msu文件
ExecWait 'wusa.exe "$INSTDIR\CamDrive\Windows6.1-KB2921916-x64.msu" /quiet /norestart' $0
DetailPrint "Windows6.1-KB2921916-x64.msu安装返回了 $0"
参考文章:http://blog.csdn.net/crazycoder8848/article/details/13703489
https://nsis-dev.github.io/NSIS-Forums/html/t-362421.html
相关文章推荐
- NSIS检测并卸载已有版本,静默卸载隐藏MessageBox
- NSIS 卸载、安装检测程序是否在运行
- NSIS根据安装文件log 卸载文件(防止误删)
- .msu格式文件跳过windowupdate检测直接安装方案(vs2015安装提示0x80240037安装失败,KB2999226无法安装)
- ClickOnce部署疑难杂症:更新时部署与应用程序标识不一致问题。要安装此应用程序,请修改此文件的清单版本或卸载之前存在的应用程序。
- NSIS安装时自动卸载老版本
- NSIS制作安装包,如何检测并卸载已有版本
- NSIS做的安装程序,可接受命令行参数,实现静默安装,静默卸载等等,真不错!-来自手册
- NSIS 静默安装 以及 在安装软件时检测软件是否启动
- NSIS——检测IIS是否安装及版本
- NSIS制作安装包,如何检测并卸载已有版本
- 如果检测到有老版本存在就先卸载老版本才形始新的安装过程
- NSIS——检测SQL Server安装版本
- Setup Factory 9安装前卸载旧版本的方法
- Python的Django安装nginx1.9.3以上版本修改配置文件的操作
- 解决Windows 7下IE11无法卸载、无法重新安装,提示安装了更新的IE版本
- android静默安装与静默卸载
- Android随笔之——静默安装、卸载
- oracle静默安装文件db_install.rsp详解
- ubuntu mysql 5.6版本的删除/安装/编码配置文件配置