一个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
祝:玩得愉快!