跳至主要內容

Windows 安装程序打包软件

大林鸱大约 3 分钟研发工具打包软件

有的时候会碰到一些在我看来比较奇特的需求,例如将 B/S 架构的程序进行单机部署,这种需求多数来源于对软件如何运行基本没了解的客户,像岁数大的、其他行业搞销售的,碰到过很多次。这个时候 inno setup 软件又能够很好的解决问题。

inno setup 主要用来打包 Windows 系统下的安装程序,简单讲就是将一些文件封装成一个可执行的 exe 安装程序,并提供安装过程的配置。

软件下载地址及版本

  • 百度网盘

链接: https://pan.baidu.com/s/1DNrLk80I2MVmJvZvEOYRzwopen in new window

提取码: m6mj

  • 版本
inno setup版本
inno setup 6.2.2

我的打包脚本

下面脚本是我将可执行 jar 包+sqlite工程打包为一个 exe 安装程序的脚本。其中 jar 包是通过注册系统服务,随机器开机自启动。项目中前后端不分离,采用 Spring Boot 和 JavaScript 研发。这种情况下,软件启动后,需要在浏览器中访问,但是客户要求像 PC 端软件一样使用,而不是使用浏览器,那就需要用 Electron 再包一层,这不是这篇博文需要讲的内容。

关注点

  • P58,安装路经检测,路径中不要出现中文及特殊字符。
  • P52,安装时执行 bat 脚本,可以将服务注册内容放到 bat 脚本中。
  • P55,卸载时执行 bat 脚本,可以注销服务。

脚本内容

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "XX报价软件"
#define MyAppDirName "cy"
#define MyAppVersion "20240402"
#define MyAppPublisher "XX"
#define MyAppURL "https://www.gremlins-books.com/"
#define MyAppExeName "XX报价软件.exe"
#define MyAppDefaultDirName "D:\"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
AppId={{XXXXE8CC-XXXX-XXXX-XXXX-300FED84XXXX}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={#MyAppDefaultDirName}\{#MyAppDirName}
DisableProgramGroupPage=yes
; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。
;PrivilegesRequired=lowest
OutputBaseFilename=XX报价软件_{#MyAppVersion}_setup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
PrivilegesRequired=admin
Uninstallable=yes
UninstallDisplayName={#MyAppName}

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:\CYOfferTool\exe\wss\{#MyAppName}.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\CYOfferTool\exe\wss\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

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

[UninstallRun]
Filename: "{app}\remove.bat"; Flags: skipifdoesntexist

[Code]
// 检查安装路径是否是英文
function IsEnglishStr(file: String): Boolean;
var
  value: Integer;
  len: Integer;
  i: Integer;
begin
  Result := true;
  len := length(file);
for i := 1 to len do
  begin
  // 将字符转成ascii值
  value := ord(file[i]);
  // 根据字符的ascii码值判断字符是否为中文
  if (value < 41) or (value > 122) then
    begin
      Result := false;
    end;
  end;
end;

// 选择安装路径下一步按钮触发事件,返回false则不会跳到下一步
function NextButtonClick(CurPageID:Integer):Boolean;
begin
  Result := True;
  if (CurPageID = wpSelectDir) then
    begin
    if(IsEnglishStr(WizardDirValue) = false) then
      begin
      Result := False;
      MsgBox('路径中不要出现中文及特殊字符!', mbError, MB_OK);
      end;
    end;
end;

上次编辑于: