最近安排我弄程序的打包工作,然后叫我接触Inno Setup打包软件。

说实话,第一次弄,什么都不懂,就不断Baidu,当然很多都没有,只有看文档了!

前面打包程序部分都还好,都完成了,但是后来说要捆绑组建,这个可把我难住了,最开始我是把组建添加进去,然后安装程序后启动组建安装,这样的缺陷多的数不清。

而后,把组建捆绑到tmp中安装,但是也是存在问题,因为用户要是在安装过程中取消了,那自己的程序也没法跑了!

而后又加入了组建的安装检测,在最后一步的时候检测是否正确安装(通过扫描注册表),假如成功则完成,假如不成功则启动程序删除!

这样基本解决了,但是感觉好麻烦,好累赘!

而后又想到了,为什么不在开始就检测呢,如果没有则安装,安装失败则退出整个程序安装!

而后就开始了我的一点点的改动,完成。

最后代码如下:

[Files]
Source: "NET2.exe"; DestDir: "{tmp}"; Flags: ignoreversion
[code]
function NeedInstallDotNet(): Boolean;
varsuccess: boolean;install: cardinal;
beginsuccess := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727', 'Install', install);Result := not(success and (install = 1));
end;function InitializeSetup(): Boolean;
var ResultCode: Integer;
beginResult :=true;if (NeedInstallDotNet) thenbeginMsgBox('您的电脑需要先安装Microsoft .NET Framework 2.0 SP2组建.' + #13 + '请等待组建加载完成并完成组建安装后再进行程序的安装.',mbError, MB_OK);ExtractTemporaryFile('NET2.exe'); Exec(ExpandConstant('{tmp}\NET2.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); end;if (NeedInstallDotNet) thenbeginMsgBox('您的组建安装失败,程序将退出安装.',mbError, MB_OK);Result :=false; //安装程序退出end else beginResult :=true;  //安装程序继续end;
end;

完整的项目:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!#define MyCompany "Broadinter"
#define MyAppName "Prober"
#define MyAppVersion "3.0.0"
#define MyAppPublisher "Broadinter, Inc."
#define MyAppURL "http://www.broadinter.com/"
#define MyAppId "{55E402DD-B073-4CDF-8AA7-D52FDC5B348E}"
#define MyAppServeKiwi "kiwi.exe"
#define MyAppServeWatchdog "kiwi_watchdog.exe"
#define MyFormationDotNetName "NetFx20SP2_x86.exe"      [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={{#MyAppId}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
AppCopyright=Copyright (C) 2013 {#MyAppPublisher}
DefaultDirName={pf}\{#MyCompany}
DefaultGroupName={#MyCompany}
AllowNoIcons=yes
LicenseFile=eula.rtf
OutputDir=..\Setup
OutputBaseFilename=setup
SetupIconFile=setup.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
WizardImageFile=Image.bmp
WizardSmallImageFile=SmallImage.bmp [Languages]
Name: "chinesesimplified"; MessagesFile: "ChineseSimplified.isl"[Files]
Source: "..\Source\Prober\*"; DestDir: "{app}\Prober"; Flags: ignoreversion recursesubdirs createallsubdirs;Source: "..\Source\Selections\network.conf"; DestDir: "{app}\Prober"; Flags: ignoreversion onlyifdoesntexist uninsneveruninstall; Check: NeedInstallNetworkConfig;
Source: "..\Source\Selections\probe.conf"; DestDir: "{app}\Prober"; Flags: ignoreversion onlyifdoesntexist uninsneveruninstall; Check: NeedInstallProbeConfig; AfterInstall: MyAfterInstall;Source: "..\Source\Prober_Update\*"; DestDir: "{app}\Prober_Update"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: "..\Source\Prober_Watchdog\*"; DestDir: "{app}\Prober_Watchdog"; Flags: ignoreversion recursesubdirs createallsubdirs;Source: "..\Source\Selections\NetFx20SP2_x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion; Check: NeedInstallDotNet;
Source: "..\Source\Selections\IE8-WindowsServer2003-x86-CHS.exe"; DestDir: "{tmp}"; Flags: ignoreversion; Check: NeedInstallIE;
Source: "..\Source\Selections\Flashplayer11_7r700_202_winax.exe"; DestDir: "{tmp}"; Flags: ignoreversion; Check: NeedInstallFlash;[Run]
Filename: "{app}\Prober\{#MyAppServeKiwi}"; Parameters: "-i Prober"; WorkingDir: "{app}\Prober"; StatusMsg: "正在安装Prober服务..."; BeforeInstall: BeforeInstallDelete;
Filename: "{app}\Prober\{#MyAppServeKiwi}"; Parameters: "-s Prober"; WorkingDir: "{app}\Prober"; StatusMsg: "正在开启Prober服务..."
Filename: "{app}\Prober_Watchdog\{#MyAppServeWatchdog}"; Parameters: "-i Prober_Watchdog"; WorkingDir: "{app}\Prober_Watchdog"; StatusMsg: "正在安装Prober_Watchdog服务..."
Filename: "{app}\Prober_Watchdog\{#MyAppServeWatchdog}"; Parameters: "-s Prober_Watchdog"; WorkingDir: "{app}\Prober_Watchdog"; StatusMsg: "正在开启Prober_Watchdog服务..."
Filename: "{tmp}\IE8-WindowsServer2003-x86-CHS.exe"; Parameters: " "; WorkingDir: "{tmp}"; StatusMsg: "正在安装IE8..."; Check: NeedInstallIE
Filename: "{tmp}\Flashplayer11_7r700_202_winax.exe"; Parameters: "/install"; WorkingDir: "{tmp}"; StatusMsg: "正在安装Flashplayer11..."; Check: NeedInstallFlash[UninstallRun]
Filename: "{app}\Prober\{#MyAppServeKiwi}"; Parameters: "-p Prober"; WorkingDir: "{app}\Prober"; StatusMsg: "正在停止Prober服务"
Filename: "{app}\Prober\{#MyAppServeKiwi}"; Parameters: "-u Prober"; WorkingDir: "{app}\Prober"; StatusMsg: "正在卸载Prober服务"
Filename: "{app}\Prober_Watchdog\{#MyAppServeWatchdog}"; Parameters: "-p Prober_Watchdog"; WorkingDir: "{app}\Prober_Watchdog"; StatusMsg: "正在停止Prober_Watchdog服务"
Filename: "{app}\Prober_Watchdog\{#MyAppServeWatchdog}"; Parameters: "-u Prober_Watchdog"; WorkingDir: "{app}\Prober_Watchdog"; StatusMsg: "正在卸载Prober_Watchdog服务"[Code]
var//探针配置页面UserPage: TInputQueryWizardPage;//是否运行了卸载IsUninstallRuned: Boolean;//是否保存配置文件IsSaveConfig: Boolean;//配置属性ConfigBool: Boolean;    //CheckBoxCB_IE: TNewCheckBox;CB_Flash: TNewCheckBox;{--检检测是否已经安装软件--}
function CheckHaveApp(): Boolean;
varResultStr: String;ResultCode: Integer;
beginif RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'UninstallString', ResultStr) then beginif (MsgBox('检测到你已安装本软件,是否卸载?', mbConfirmation, MB_YESNO) = IDYES) then beginResultStr := RemoveQuotes(ResultStr);Exec(ResultStr, '/silent', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);//二次检测是否卸载if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'UninstallString', ResultStr) then beginresult:=false;end else beginresult:=true;end;  end;end else beginresult:=true;end;
end;{--检测是否需要安装NET组建--}
function NeedInstallDotNet(): Boolean;
varsuccess: boolean;install: cardinal;
beginsuccess := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727', 'Install', install);Result := not(success and (install = 1));
end;{--检测是否需要IE组建--}
function NeedInstallIE(): Boolean;
beginResult := CB_IE.Checked;
end;{--检测是否需要Flash组建--}
function NeedInstallFlash(): Boolean;
beginResult := CB_Flash.Checked;
end;{--检测是否需要安装Network配置文件--}
function NeedInstallNetworkConfig(): Boolean;
beginif FileExists(ExpandConstant('{app}') + '\Prober\network.conf') then beginResult := False;end else beginResult := True; end;
end;{--检测是否需要安装Probe配置文件--}
function NeedInstallProbeConfig(): Boolean;
beginif FileExists(ExpandConstant('{app}') + '\Prober\probe.conf') then beginResult := False;end else beginResult := True; end;
end;{--检检测是否已经IE8--}
function CheckHaveIE8(): Boolean;
varResultStr: String;ResultCode: Integer;
beginRegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Internet Explorer', 'Version', ResultStr);if ResultStr = '8.0.6001.18702' then beginresult := False;end else beginresult := True;end;
end;{--启动服务前删除多余数据--}
procedure BeforeInstallDelete();
varwhileLen: Integer;
beginwhileLen := 0;while  whileLen <> 5 dobeginif(FileExists(ExpandConstant('{app}') + '\Prober\probe.db')) then beginDeleteFile(ExpandConstant('{app}'+ '\Prober\probe.db'));whileLen:= whileLen+1;end else beginwhileLen := 5;end;end;if(FileExists(ExpandConstant('{app}') + '\Prober\probe.db')) then beginMsgBox('文件“\Prober\probe.db”清理失败!',mbError, MB_OK);end;DelTree(ExpandConstant('{app}'+ '\Prober\log'), True, True, True);DelTree(ExpandConstant('{app}'+ '\Prober\mq_ext'), True, True, True);
end;{--开始前检测--}
function InitializeSetup(): boolean;
varResultStr: String;ResultCode: Integer;whileLen: Integer;
beginCheckHaveIE8;//是否已经安装本软件whileLen := 0;while  whileLen <> 3 dobeginif(CheckHaveApp) then beginresult:=true;whileLen := 3;end else beginresult:=false;whileLen:= whileLen+1;end;end;//是否需要组建if(result) thenbeginif (NeedInstallDotNet) thenbeginMsgBox('您的电脑需要先安装Microsoft .NET Framework 2.0 SP2组建.' + #13 + '请等待组建加载完成并完成组建安装后再进行程序的安装.',mbError, MB_OK);ExtractTemporaryFile('{#MyFormationDotNetName}'); Exec(ExpandConstant('{tmp}\{#MyFormationDotNetName}'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); end;if (NeedInstallDotNet) thenbeginMsgBox('您的组建安装失败,程序将退出安装.',mbError, MB_OK);Result :=false; //安装程序退出end else beginResult :=true;  //安装程序继续end;end;
end;{-- 创建插件页面 --}
procedure CreateTheWizardPages;
varPage: TWizardPage;Button, FormButton: TNewButton;Panel: TPanel;HaveIE8Bool: Boolean;
beginPage := CreateCustomPage(wpWelcome, '插件安装', '请选择您需要安装的插件');HaveIE8Bool := CheckHaveIE8;CB_IE := TNewCheckBox.Create(Page);CB_IE.Top := ScaleY(35);CB_IE.Left :=  ScaleY(40);CB_IE.Width := Page.SurfaceWidth div 2;CB_IE.Height := ScaleY(17);CB_IE.Caption := '安装IE8插件';CB_IE.Checked := HaveIE8Bool;CB_IE.Enabled := HaveIE8Bool;CB_IE.Parent := Page.Surface;CB_Flash := TNewCheckBox.Create(Page);CB_Flash.Top := CB_IE.Top + CB_IE.Height + ScaleY(8);CB_Flash.Left :=  ScaleY(40);CB_Flash.Width := Page.SurfaceWidth div 2;CB_Flash.Height := ScaleY(17);CB_Flash.Caption := '安装Flashplayer11插件';CB_Flash.Checked := True;CB_Flash.Parent := Page.Surface;end;{--- 页面初始化 --}
procedure InitializeWizard;
begin{-- 创建插件页 --}CreateTheWizardPages;{-- 创建配置页 --}UserPage := CreateInputQueryPage(wpReady,'配置', '请进行如下配置,然后进入下一步','请确保填写正确的信息');UserPage.Add('服务端IP', False);UserPage.Add('监测点ID', False);ConfigBool := True;
end;{-- 下一步按钮事件响应 --}
function NextButtonClick(CurPageID: Integer): Boolean;
beginResult := True;if CurPageID = UserPage.ID then beginif UserPage.Values[0] = '' then beginMsgBox('请填写服务端IP', mbError, MB_OK);Result := False;end elseif UserPage.Values[1] = '' then beginMsgBox('请填写监测点ID', mbError, MB_OK);Result := False;end;end;if CurPageID = wpReady then beginif FileExists(ExpandConstant('{app}') + '\Prober\network.conf') and FileExists(ExpandConstant('{app}') + '\Prober\probe.conf') then beginConfigBool := False;end;end;
end;{-- 页面跳转时 实现是否允许跳转 --}
function ShouldSkipPage(PageID: Integer): Boolean;
beginResult := False;if PageID = UserPage.ID then beginif ConfigBool = False then beginResult := True;end;end;
end;{-- 去字符串空格 --}
function StringTrim(a: string): string;
beginResult := a;while pos(' ',Result)<>0 dodelete(Result,pos(' ',Result),1);
end;{-- 方法: 实现对配置文件拷贝后进行处理 --}
procedure MyAfterInstall();
varXMLDoc0: Variant;XMLDoc1: Variant; s: string;
beginif ConfigBool then begintryXMLDoc0 := CreateOleObject('MSXML2.DOMDocument');XMLDoc0.async := False;XMLDoc0.resolveExternals := False;XMLDoc0.load(ExpandConstant('{app}') + '\Prober\network.conf');XMLDoc0.selectSingleNode('//channel[@name=''balance'']').attributes.getNamedItem('peer_addr').text := StringTrim(UserPage.Values[0]);XMLDoc0.save(ExpandConstant('{app}') + '\Prober\network.conf');exceptRaiseException('未能正确配置服务端IP,请检查network.conf');end;tryXMLDoc1 := CreateOleObject('MSXML2.DOMDocument');XMLDoc1.async := False;XMLDoc1.resolveExternals := False;XMLDoc1.load(ExpandConstant('{app}') + '\Prober\probe.conf');XMLDoc1.selectSingleNode('//mid').text := StringTrim(UserPage.Values[1]);XMLDoc1.save(ExpandConstant('{app}') + '\Prober\probe.conf');exceptRaiseException('未能正确配置监测点ID,请检查probe.conf');end;end;
end;{-- 卸载程序时对用户是否保留插件 --}
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
varXMLDoc0: Variant;XMLDoc1: Variant;
begin//进入卸载后改变状态IsUninstallRuned := true;if CurUninstallStep = usUninstall then beginif MsgBox('是否需要保留配置文件?', mbConfirmation, MB_YESNO) = IDYES then beginIsSaveConfig := True;          tryXMLDoc0 := CreateOleObject('MSXML2.DOMDocument');XMLDoc0.async := False;XMLDoc0.resolveExternals := False;XMLDoc0.load(ExpandConstant('{app}') + '\Prober\network.conf');XMLDoc0.save(ExpandConstant('{app}') + '\Prober\network_tmp.conf');XMLDoc1 := CreateOleObject('MSXML2.DOMDocument');XMLDoc1.async := False;XMLDoc1.resolveExternals := False;XMLDoc1.load(ExpandConstant('{app}') + '\Prober\probe.conf');XMLDoc1.save(ExpandConstant('{app}') + '\Prober\probe_tmp.conf');exceptend;end else beginIsSaveConfig := False;end;     end;
end;{-- 删除后操作 对文件进行一定的处理 --}
procedure DeinitializeUninstall();
varXMLDoc0: Variant;XMLDoc1: Variant;
begin//首先判断是否进入了卸载if IsUninstallRuned then beginif IsSaveConfig then begintry          DeleteFile(ExpandConstant('{app}'+ '\Prober\probe.db'));DelTree(ExpandConstant('{app}'+ '\Prober\log'), True, True, True);DelTree(ExpandConstant('{app}'+ '\Prober\mq_ext'), True, True, True);DelTree(ExpandConstant('{app}'+ '\Prober_Update'), True, True, True);DelTree(ExpandConstant('{app}'+ '\Prober_Watchdog'), True, True, True);exceptMsgBox('清空程序日志及数据库缓存失败!', mbInformation, MB_OK);end;tryXMLDoc0 := CreateOleObject('MSXML2.DOMDocument');XMLDoc0.async := False;XMLDoc0.resolveExternals := False;XMLDoc0.load(ExpandConstant('{app}') + '\Prober\network_tmp.conf');XMLDoc0.save(ExpandConstant('{app}') + '\Prober\network.conf');XMLDoc1 := CreateOleObject('MSXML2.DOMDocument');XMLDoc1.async := False;XMLDoc1.resolveExternals := False;XMLDoc1.load(ExpandConstant('{app}') + '\Prober\probe_tmp.conf');XMLDoc1.save(ExpandConstant('{app}') + '\Prober\probe.conf');exceptMsgBox('保留配置文件失败!', mbInformation, MB_OK);end;try          DeleteFile(ExpandConstant('{app}'+ '\Prober\network_tmp.conf'));DeleteFile(ExpandConstant('{app}'+ '\Prober\probe_tmp.conf'));exceptMsgBox('清空配置文件缓存失败!', mbInformation, MB_OK);end; end else beginDelTree(ExpandConstant('{app}'), True, True, True);end;end;
end;

[Other] Inno Setup 使用心德-一个完整的项目 包括.NET组建捆绑 去空格等相关推荐

  1. l完整的计算机系统,一个完整的计算机系统包括

    --------------------------------------------------正文内容开始-------------------------------------------- ...

  2. BAT面试题13:请简要说说一个完整机器学习项目的流程

    BAT面试题13:请简要说说一个完整机器学习项目的流程 https://mp.weixin.qq.com/s/HiqC1MCb5TEBUxjiYvB7bA 摘要:本文描述机器学习任务的"OO ...

  3. 测试环境搭建流程_案例解析:一个完整的项目测试方案流程,应该是怎么的?...

    作为一名软件测试工程师,为项目制作完成的测试方案并执行,是我们日常工作的重要部分,同时,也是一名合格的软件测试工程师应有的专业素养.那么,很多小白和测试新手肯定要问了:一个完整的项目测试方案流程,应该 ...

  4. FX5u控制4个伺服,一个完整的项目 程序用 标签分层,说明了定位控制中的公共参数设定、回原点、

    FX5u控制4个伺服,一个完整的项目 程序用 标签分层,说明了定位控制中的公共参数设定.回原点.JOG手动.绝对定位.相对定位.控制等部分,威纶程序报警界面.多个机种选择,手动,自动,暂停,包括有: ...

  5. vue.js — 安装Webpake创建一个完整的项目并上传至码云

    vue.js - 安装Webpake创建一个完整的项目并上传至码云 今天总结一下之前几天学习的一整套的创建项目方法: 前提条件:已安装node.js.npm/cnpm最新版本.vue-cli. VS ...

  6. FX5u控制4个伺服,一个完整的项目 回原点、JOG手动、绝对定位、相对定位、控制等部分

    FX5u控制4个伺服,一个完整的项目 程序用 标签分层,说明了定位控制中的公共参数设定.回原点.JOG手动.绝对定位.相对定位.控制等部分,威纶程序报警界面.多个机种选择,手动,自动,暂停,包括有: ...

  7. 案例解析:一个完整的项目测试方案流程,应该是怎么的?

    作为一名软件测试工程师,为项目制作完成的测试方案并执行,是我们日常工作的重要部分,同时,也是一名合格的软件测试工程师应有的专业素养.那么,很多小白和测试新手肯定要问了:一个完整的项目测试方案流程,应该 ...

  8. 2 一个完整的计算机系统包括,一个完整的计算机系统包括(19页)-原创力文档...

    PAGE 一. 1). 一个完整的计算机系统包括 A). 主机.键盘和显示器 B). 计算机与外部设置 C). 硬件系统和软件系统 D). 系统软件与应用软件 2). 在多媒体计算机系统中,CD-RO ...

  9. 本人亲测-inno setup打包EXE(较完整实例)

    ; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING ...

  10. 人生就是一个完整的项目

    人生的七个不要 在朋友的QQ签名里看到,深有同感 人生的七个不要: 1)不要等到需要了,才积累人脉 2)不要等到有时间了,才去读书 3)不要等到身无分文,才想起储蓄 4)不要等到痛苦了,才放下 5)不 ...

最新文章

  1. [转]给UIImage添加圆角(圆角矩形),也可用于CCSprite
  2. 22.PATH环境变量
  3. Spring的@Transactional注解踩坑
  4. 【Processing学习】 - 公交车马路动态绘制
  5. Selenium alert 弹窗处理
  6. Linux:查看文件夹大小
  7. Aizu0189 Convenient Location【Floyd算法】
  8. css 里层元素撑不开外层元素
  9. MT 3DGIS 试用版本开发包及教程下载地址
  10. linux 安卓 挂pt,如何挂PT: Ubuntu / CentOS 7安装Deluge
  11. 电脑怎么连接隐藏的无线WiFi信号呢
  12. 网贷查询接口开发 网贷黑名单查询 个人网贷黑名单查询
  13. SQLServer锁表
  14. http91spwp index.php,index.php
  15. Xshell 6的 InstallShield: 1628 完成基于脚本的安装失败
  16. mysql主从配置duxi_mysql主从配置
  17. ac.find_template 踩坑,寻找相似图片,安卓自动化代码
  18. 分布式技术(下)-RedisFastDFSRabbitMQ
  19. 苏州运维交流研讨会-走进玩友时代顺利举办
  20. mac按键难回弹(按下去软软的)

热门文章

  1. matlab课堂笔记,厦门大学matlab第四次课程笔记 PTB的简单讲解
  2. 【ide】myeclipse项目右键没有configure
  3. Raki的网络流24题题解总结
  4. python遍历目录下所有文件
  5. iOS开发日记39-上传ERROR-90535,90529,90049
  6. 『电脑技巧』破解Win7/Win8登录密码
  7. 地址栏js的写法(转载)
  8. C# 网页自动填表自动登录 .
  9. sqlite3 判断数据库和表的状态
  10. java系统排序_java各种排序实现