使用Inno Setup制作安装程序

  使用VS自带的部署工具制作出的安装程序感觉比较死板,Inno Setup(以下简称IS)即开源又灵活,比较实用,以下是笔者近期制作的一个安装程序的IS Pascal源码,带更新前先卸载旧版本;.net环境检测与自动安装功能,后面有Inno Setup及源码下载链接,供参考:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "xNode客户端"
#define MyAppVersion "2.15"
#define MyAppPublisher "Hengsion, Inc."
#define MyAppURL "http://www.hengsion.com/"
#define MyAppExeName "xNode客户端V2.15"
#define MyAppExeFile "xNode客户端V2.15.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={{43A88340-5401-4B4E-888A-CAECCB6148EF}
AppName={#MyAppName}
;应用程序互斥标记,检测在更新或卸载的过程中应用程序是否已在运行
AppMutex={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
;安装目录名称
DefaultDirName={pf}\{#MyAppName}
;安装在早期的目录下
UsePreviousAppDir=yes
;开始菜单程序组的名称
DefaultGroupName={#MyAppName}
;生成的安装程序文件保存路径
OutputDir=C:\Users\Administrator\Desktop
;生成的安装程序文件名称
OutputBaseFilename=xNode客户端V2.15安装文件
SetupIconFile=E:\Project\xNode\Client\xNodeClient\40_40.ico
Compression=lzma
SolidCompression=yes
;安装程序首个界面的左边图片
WizardImageFile=D:\Program Files\Inno Setup 5\WizModernImage-IS.bmp          
;安装程序第二个界面的右上角图片
WizardSmallImageFile=D:\Program Files\Inno Setup 5\WizModernSmallImage-IS.bmp

[Languages]
Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"

;用户定制任务
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}";

;文件安装
[Files]
Source: "E:\Project\xNode\版本发布\Client\V2.15\xNode客户端V2.15.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\UpgradeLog.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\xNodeClientBLL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\xNodeClientDAL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\xNodeClientModel.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\xNode客户端V2.15.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Project\xNode\版本发布\Client\V2.15\Images\*"; DestDir: "{app}\Images"; Flags: ignoreversion recursesubdirs createallsubdirs
;.net 4.0安装文件路径
Source: "D:\DevelopTools\微软官网下载的文件\dotNetFx40_Full_x86_x64.exe"; DestDir: "{tmp}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

;开始菜单与桌面的文件名称设置
[Icons]
Name: "{group}\{#MyAppExeName}"; Filename: "{app}\{#MyAppExeFile}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppExeName}"; Filename: "{app}\{#MyAppExeFile}"; Tasks: desktopicon

[Code]
function CheckDotNet4_0():boolean; 
begin
Result:= RegKeyExists(HKLM, 'SOFTWARE\Microsoft\.NETFramework\policy\v4.0');
end;

function InitializeSetup(): Boolean;
var ResultStr: String;
var ResultCode: Integer;
begin
  if not CheckDotNet4_0() then
    begin
      MsgBox('检测到系统没有安装.Net Framework4.0环境,即将安装.net4.0!',mbInformation,MB_OK);
      ExtractTemporaryFile('dotNetFx40_Full_x86_x64.exe');  //解压安装安装文件到临时文件夹
      Exec(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);  //安装.net
      Result:=true;
    end
  else
    begin
      Result:=true;
    end

  //以下代码是安装前卸载老版本  
  if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{43A88340-5401-4B4E-888A-CAECCB6148EF}_is1', 'UninstallString', ResultStr) then 
    begin 
      ResultStr := RemoveQuotes(ResultStr); 
      Exec(ResultStr, '/VERYSILENT', '',SW_HIDE, ewWaitUntilTerminated, ResultCode); //第二个参数为'/VERYSILENT',是在执行反安装模式的时候是静默模式,用户在不知觉中删掉旧的版本 
    end
end;

[Run]
Filename: "{app}\{#MyAppExeFile}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent


 Inno Setup官方下载地址:Inno Setup下载

笔者近期的一个项目源码:http://download.csdn.net/detail/lanmangfeige/7840121

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值