美文网首页
inno setup打包多个exe、msi 自动检测.net f

inno setup打包多个exe、msi 自动检测.net f

作者: 遗失的美好灬 | 来源:发表于2021-11-14 10:07 被阅读0次
  • 新建一个空白脚本
    #define MyAppName "传奇霸业"
    #define MyAppVersion "1.8.8.8"
    #define MyAppPublisher "霸业科技"
    #define MyAppURL "https://www.baye.com/"
    #define MyAppExeName "BY.exe"

    [Setup]
    ; 注: AppId的值为单独标识该应用程序。
    ; 不要为其他安装程序使用相同的AppId值。
    ; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
    AppId={{C65D84B0-690E-470E-B828-9636F696B92E}
    AppName={#MyAppName}
    AppVersion={#MyAppVersion}
    ;AppVerName={#MyAppName} {#MyAppVersion}
    AppPublisher={#MyAppPublisher}
    AppPublisherURL={#MyAppURL}
    AppSupportURL={#MyAppURL}
    AppUpdatesURL={#MyAppURL}
    DefaultDirName={autopf}\{#MyAppName}
    DisableProgramGroupPage=yes
    ; [Icons] 的“quicklaunchicon”条目使用 {userappdata},而其 [Tasks] 条目具有适合 IsAdminInstallMode 的检查。
    UsedUserAreasWarning=no
    ; 移除以下行,以在管理安装模式下运行(为所有用户安装)。
    PrivilegesRequired=admin
    OutputBaseFilename={#MyAppName}
    Compression=lzma
    SolidCompression=yes
    WizardStyle=modern

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

    [Tasks]
    Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
    Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
//组件安装方式
    [Types]
    Name: win32; Description: Window 默认环境组件安装
    Name: custom; Description:  自定义环境组件安装; Flags: iscustom

    //组件列表选择项
    [Components]
    Name: MainApp; Description: {#MyAppName}主程序; Types: win32 custom ; Flags: fixed
    Name: net; Description: 微软官方 .Net Framework 4.6.1 运行库; Types: win32 custom;Flags: fixed
    Name: BYCJ; Description: 霸业插件; Types: win32 custom;Flags: fixed

    //源文件所在目录
    [Files]
    Source: "D:\Develop\cs\install\Release\BY.exe"; DestDir: "{app}"; Flags: ignoreversion;Components: MainApp
    Source: "D:\Develop\cs\install\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
    Source: "D:\Develop\cs\install\dotNetFx461_Full_x86_x64.exe"; DestDir: "{app}"; Flags: ignoreversion  ; Components: net; AfterInstall: net
    Source: "D:\Develop\cs\install\BYCJ.msi"; DestDir: "{app}"; Flags: ignoreversion  ; Components: BYCJ; AfterInstall: BYCJ
    ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

    [Icons]
    Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
    Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
    Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

    [Run]
    Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
   [CODE]
    const CDotNetSetupFile = 'dotNetFx461_Full_x86_x64.exe';
    function IsDotNetDetected(version: string; service: cardinal): boolean;
    // Indicates whether the specified version and service pack of the .NET Framework is installed.
    //
    // version -- Specify one of these strings for the required .NET Framework version:
    //    'v1.1'          .NET Framework 1.1
    //    'v2.0'          .NET Framework 2.0
    //    'v3.0'          .NET Framework 3.0
    //    'v3.5'          .NET Framework 3.5
    //    'v4\Client'     .NET Framework 4.0 Client Profile
    //    'v4\Full'       .NET Framework 4.0 Full Installation
    //    'v4.5'          .NET Framework 4.5
    //    'v4.5.1'        .NET Framework 4.5.1
    //    'v4.5.2'        .NET Framework 4.5.2
    //    'v4.6'          .NET Framework 4.6
    //    'v4.6.1'        .NET Framework 4.6.1
    //    'v4.6.2'        .NET Framework 4.6.2
    //    'v4.7'          .NET Framework 4.7
    //    'v4.7.1'        .NET Framework 4.7.1
    //    'v4.7.2'        .NET Framework 4.7.2
    //    'v4.8'          .NET Framework 4.8
    //
    // service -- Specify any non-negative integer for the required service pack level:
    //    0               No service packs required
    //    1, 2, etc.      Service pack 1, 2, etc. required
    var
    key, versionKey: string;
    install, release, serviceCount, versionRelease: cardinal;
    success: boolean;
    begin
    versionKey := version;
    versionRelease := 0;

    // .NET 1.1 and 2.0 embed release number in version key
    if version = 'v1.1' then begin
    versionKey := 'v1.1.4322';
    end
    else if version = 'v2.0' then begin
    versionKey := 'v2.0.50727';
    end

    // .NET 4.5 and newer install as update to .NET 4.0 Full
    else if Pos('v4.', version) = 1 then begin
    versionKey := 'v4\Full';
    case version of
    // from url https://docs.microsoft.com/zh-cn/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
    'v4.5':   versionRelease := 378389;
    'v4.5.1': versionRelease := 378675; // 378758 on Windows 8 and older
    'v4.5.2': versionRelease := 379893;
    'v4.6':   versionRelease := 393295; // 393297 on Windows 8.1 and older
    'v4.6.1': versionRelease := 394254; // 394271 on Windows 8.1 and older
    'v4.6.2': versionRelease := 394802; // 394806 on Windows 8.1 and older
    'v4.7':   versionRelease := 460798; // 460805 On all other Windows operating systems (including other Windows 10 operating systems)
    'v4.7.1': versionRelease := 461308; // 461310 On all other Windows operating systems (including other Windows 10 operating systems)
    'v4.7.2': versionRelease := 461808; // 461814 On all Windows operating systems other than Windows 10 April 2018 Update and Windows Server, version 1803
    'v4.8'  : versionRelease := 528040; // On Windows 10 May 2019 Update and Windows 10 November 2019 Update: 528040; On Windows 10 May 2020 Update and Windows 10 October 2020 Update: 528372; On all other Windows operating systems (including other Windows 10 operating systems): 528049
    end;
    end;

    // installation key group for all .NET versions
    key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + versionKey;

    // .NET 3.0 uses value InstallSuccess in subkey Setup
    if Pos('v3.0', version) = 1 then begin
    success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
    end else begin
    success := RegQueryDWordValue(HKLM, key, 'Install', install);
    end;

    // .NET 4.0 and newer use value Servicing instead of SP
    if Pos('v4', version) = 1 then begin
    success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
    end else begin
    success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
    end;

    // .NET 4.5 and newer use additional value Release
    if versionRelease > 0 then begin
    success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
    success := success and (release >= versionRelease);
    end;

    result := success and (install = 1) and (serviceCount >= service);
    end;

    //net 4.6.1
    procedure net;
    var RetCode:Integer;
    begin

    if not IsDotNetDetected('v4.6.1', 0) then begin
    ShellExec('open', ExpandConstant('{app}\'+CDotNetSetupFile), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, RetCode);
    if RetCode <> 0 then
    begin
    MsgBox(SysErrorMessage(RetCode) + ' 请关闭360等杀毒软件', mbInformation, MB_OK);
    end

    end
    end;

    //安装BYCJ
    procedure BYCJ;
    var
    RetCode: integer;
    begin
    ShellExec('open', ExpandConstant('{app}\BYCJ.msi'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, RetCode);
    if RetCode <> 0 then
    MsgBox(SysErrorMessage(RetCode), mbInformation, MB_OK);
    end;
  • 目录结构
image
  • 解释
    [Components]下的Flags字段可以选择
    **Flags**

    此参数是一组额外选项。可以通过用空格分隔它们来使用多个选项。支持以下选项:

    checkablealone

    指定当一个组件的子组件选中时,该组件是否可以选中。按默认值,如果没有 `Components` 参数直接引用到该组件,未选中所有子组件将会使该组件变成未选中状态。

    dontinheritcheck

    指定当该组件的上级被选中时,该组件应该不自动变成已选中状态。这对顶层的组件不影响,且不能与 `exclusive` 标志组合使用。

    exclusive

    告诉安装程序这个组件与它的也使用 `exclusive` 标志的同级组件是互相排斥的。

    fixed

    告诉安装程序这个组件不能在安装期间被最终用户手动选择或取消选择。

    restart

    告诉安装程序如果用户安装了这个组件,将询问用户重新启动系统,不管它是不是需要(例如,因为 [Files] 区段条目用了 `restartreplace` 标志)。有点象 [AlwaysRestart](topic_setup_alwaysrestart.htm),但不是每个组件。

    disablenouninstallwarning

    如果这个组件已经安装在用户机器中,重新安装时在用户取消这个组件选择后,这条标志告诉安装程序不警告用户不卸载该组件。

    考虑到你的组件的复杂性,你可以尝试使用 [InstallDelete] 区段和该标志为自动“卸载”取消选定的组件。

[Files]下的Source字段替换成自己的目录,Components字段对应[Components]

  • 效果


    image

相关文章

网友评论

      本文标题:inno setup打包多个exe、msi 自动检测.net f

      本文链接:https://www.haomeiwen.com/subject/egbttrtx.html