一个Inno Setup创建安装包的例子

环境说明

  • Inno Setup 版本:5.5.9

特色说明

[1] 安装前检测应用是否运行,若运行则提示关闭(未借助额外dll,使用系统命令tasklist)
[2] 针对安装环境缺少Microsoft Visual C++ 2015(==请自助修改==)的环境自动执行安装

制作安装包

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

#define MyGroupName "**软件\软件名称"
#define MyAppName "软件名称"  
#define MyUninstallAppName "卸载软件名称"
#define MyAppVersion ""  
#define MyAppPublisher ""  
#define MyAppURL ""  
#define MyAppExeName "" 
#define MyAppDir "" 
#define MyAppSetupDir ""

[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=
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyGroupName}
DisableProgramGroupPage=yes
OutputDir={#MyAppSetupDir}
OutputBaseFilename=setup
SetupIconFile={#MyAppDir}\synchelper.ico
Compression=lzma
SolidCompression=yes

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

[Tasks]
Name: "desktopIcon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
;Name: "quickLaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "{#MyAppDir}\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"
Name: "{group}\{#MyUninstallAppName}"; Filename: "{uninstallexe}"  
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
;Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

[Run]
;;安装后检测是否安装运行库
Filename: "{app}\vcredist\vcredist_x86.exe"; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "正在安装Microsoft Visual C++ 2015 Redistributable(x86) - 14.0.24125..."; Check:  IsNeedInstallVC14;

;;启动软件
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent;

[Code]
//全局变量
var
 vc14Missing: Boolean;

//软件是否运行
function IsAppRunning(const FileName : string): Boolean;
var 
ProcessRunState :Integer;
begin
    result := false;
    Exec('cmd.exe', Format('/C tasklist|findstr /i %s',[FileName]), '', SW_HIDE,ewWaitUntilTerminated, ProcessRunState); 
    if (ProcessRunState = 0) then
    begin
        result := true;
    end;
end;
 
//判断函数
function IsNeedInstallVC14(): Boolean;
begin
 Result := vc14Missing;
end;

//启动前检测
function InitializeSetup(): Boolean;
var 
VCRuntime14RegPath :string;
begin
    if ( IsAppRunning('{#MyAppExeName}') ) then
    begin
        MsgBox('安装程序检测到 {#MyAppName} 正在运行!请先选择退出,再尝试安装!', mbCriticalError, MB_OK);
        result := false;
    end else
    begin
        VCRuntime14RegPath:='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{69BCE4AC-9572-3271-A2FB-9423BDA36A43}';
        if RegKeyExists(HKLM, VCRuntime14RegPath) = false then
        begin
            vc14Missing := true;
        end;
        result := true;
    end
end;

//卸载前检查
function InitializeUninstall(): Boolean;
begin
    result := true;
    if ( IsAppRunning('{#MyAppExeName}') ) then
    begin
        MsgBox('安装程序检测到 {#MyAppName} 正在运行!请先选择退出,再尝试卸载!', mbCriticalError, MB_OK);
        result := false;
    end;
end;
  • 注意

    [1] 例子中检查和安装vc-runtime仅针对x86

转载于:https://www.cnblogs.com/hejianglin/p/8474497.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值