Inno Setup 系列之先卸载以后再安装

需求
使用Inno Setup打包程序以后,不少时候咱们须要在安装文件以前卸载原有的程序而不是覆盖安装,本文的Code就是实现了这样的功能。若是想要在安装前先卸载,那么须要加下面代码,须要注意的是双星号里面的 `{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E}` 部分的改成大家本身的。网上看到有些说_is1前面用AppName,可是我这边不行,下面code中 `{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E}` 为你的程序名,能够去你的 Inno Setup 脚本中找到程序ID: AppId={`{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E}` 也能够到注冊表中确认,为防止之后忘记,在这里记录一下,方便之后使用。php

实现原理是:从注冊表 'UninstallString' 项中读取卸载信息,用Exec进行静默卸载。app

[Setup]ide

; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={**{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E}**
AppName={#MyAppName}
AppVersion={#MyAppVersion}

[Code]this

function InitializeSetup(): boolean; 
var 
ResultStr: String; 
ResultCode: Integer; 
begin 
if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E}_is1', 'UninstallString', ResultStr) then 
begin 
ResultStr := RemoveQuotes(ResultStr); 
Exec(ResultStr, '/silent', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); 
end; 
result := true; 
end;

 

静默安装,就是减小程序与用户的交互,一站式的安装过程spa

1. 静默安装参数
Inno Setup 的静默安装是经过参数来控制的.net

1.1. `/silent` 静默安装,但若是又报错,仍是会提示,而且有进度条rest

1.2. `/verysilent` 静默安装,更强制,不过是否报错,都不会有任何提示code

(注意:若是须要重启电脑,它会不提示而直接重启)blog

1.3. `/suppressmsgboxes` 由 `suppress`(抑制,镇压)和`msgboxes`(消息框),组成,表示不提示消息框ip

1.4. `/norestart` 结合1.2使用,这样就不会没有提示而直接重启了

参数用法例子:

qq.exe /silent /suppressmsgboxes

更多参数请参考官方文档:http://www.jrsoftware.org/ishelp/index.php?topic=scriptfunctions

2. 不只安装过程能够静默,卸载过程也能够实现
经常使用参数也同样,但执行的是相应的卸载程序而已

如:

uninstall.exe /silent /suppressmsgboxes

更多参数请参考官方文档:http://www.jrsoftware.org/ishelp/index.php?topic=uninstcmdline Inno Setup 中文帮助文档https://download.csdn.net/download/qq_36190858/10836946

相关文章
相关标签/搜索