Inno Setup6.2.0汉化版软件及生成安装包脚本(二)

个人研究,为了记录下打包脚本,大家也可以安装打包脚本向导一步一步生成。

下面是我打包的脚本,其中包含了安装过程中执行批处理文件,是为了安装API服务,可以参考下:

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

#define MyAppName "客户端名称"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "公司名称"
#define MyAppURL "公司网址"
#define MyAppExeName "Client.exe"
#define MyAppAssocName MyAppName + " 文件"
#define MyAppAssocExt ".exe"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
AppId={{08FBA954-A306-4782-8C02-05F3DFE01772}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
InfoBeforeFile=E:\TMT\安装说明.txt
; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。
;PrivilegesRequired=lowest
OutputBaseFilename=Setup
SetupIconFile=E:\TMT\viso.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ArchitecturesInstallIn64BitMode=x64

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

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

[Types]
Name: win64; Description: Window 默认环境组件安装
Name: custom; Description:  自定义环境组件安装; Flags: iscustom

//组件列表选择项
[Components]
Name: BYCJ; Description: HeidiSQL; Types: win64 custom

[Files]
Source: "E:\Client\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\Client\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "E:\Client\mariadb.msi"; DestDir: "{app}"; Flags: ignoreversion  ; Components: BYCJ; AfterInstall: BYCJ
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".exe"; ValueData: ""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\YourClient2023"; Flags: uninsdeletekeyifempty; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\YourClient2023"; Flags: uninsdeletekeyifempty; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"

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

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

[UninstallRun]
// 卸载应用时执行以下文件
Filename: "{app}\Server\stop.bat"; Flags: runhidden

  [Code]
  //安装BYCJ
    procedure BYCJ;
    var
    RetCode: integer;
    begin
    ShellExec('open', ExpandConstant('{app}\mariadb.msi'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, RetCode);
    if RetCode <> 0 then
    MsgBox(SysErrorMessage(RetCode), mbInformation, MB_OK);
    end;

  procedure UpdateRegistryValue();
var
  RegKey: string;
  RegValue: string;
begin
  // 尝试读取注册表值
  RegKey := 'Software\YourClient2023';
  if RegQueryStringValue(HKA, RegKey, 'Version', RegValue) then
  begin
    // 如果注册表值存在且不等于 "Updated Value",则更新它
    if RegValue <> '{#MyAppVersion}' then
    begin
      RegWriteStringValue(HKA, RegKey, 'Version', '{#MyAppVersion}');
      RegWriteStringValue(HKA, RegKey, 'InstallPath', '{app}');
    end;
  end
  else
  begin
    // 如果注册表值不存在,则创建它
    RegWriteStringValue(HKA, RegKey, 'Version', '{#MyAppVersion}');
    RegWriteStringValue(HKA, RegKey, 'InstallPath', '{app}');
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  // 在安装完成后更新注册表值
  if CurStep = ssDone then
  begin
    UpdateRegistryValue();
  end;
end;

 

posted @ 2023-12-01 14:49  小卜呦呦  阅读(425)  评论(0编辑  收藏  举报