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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36190858/article/details/86152269

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}` 也可以到注冊表中确认,为防止以后忘记,在这里记录一下,方便以后使用。

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

[Setup]

; 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]

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;

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

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

1.1. `/silent` 静默安装,但如果又报错,还是会提示,并且有进度条

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

(注意:如果需要重启电脑,它会不提示而直接重启)

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

扫描二维码关注公众号,回复: 4909172 查看本文章

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

posted @ 2018-12-16 21:14 Foryourfuture 阅读( ...) 评论( ...) 编辑 收藏

猜你喜欢

转载自blog.csdn.net/qq_36190858/article/details/86152269