inno setup打包多个exe、msi 自动检测.net framework并安装

  • 新建一个空白脚本
    #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;
  • 目录结构

  • 解释
    [Components]下的Flags字段可以选择
	**Flags**

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

	checkablealone

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

	dontinheritcheck

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

	exclusive

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

	fixed

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

	restart

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

	disablenouninstallwarning

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

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

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

  • 效果
    在这里插入图片描述
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
1. 安装Inno Setup 首先你需要下载并安装Inno Setup。你可以在官网上下载最新版的Inno Setup http://www.jrsoftware.org/isinfo.php。下载完成后,安装Inno Setup。 2. 创建一个新的安装程序 在安装程序中,点击“File”菜单,选择“New”,然后选择“Script File”来创建一个新的脚本文件。你可以在这个文件中定义你的安装程序的行为。 3. 配置安装程序 在脚本文件中,你需要配置一些信息,比如你的安装程序的名称、版本、作者等等。你可以在脚本文件中添加以下代码: [Setup] AppName=My Application AppVersion=1.5 AppPublisher=My Company AppPublisherURL=http://www.mycompany.com/ AppSupportURL=http://www.mycompany.com/support AppUpdatesURL=http://www.mycompany.com/updates DefaultDirName={pf}\My Application DefaultGroupName=My Application 4. 添加文件 在安装程序中添加文件非常简单。你只需要在脚本文件中添加以下代码: [Files] Source: "C:\MyApp\*"; DestDir: "{app}"; Flags: recursesubdirs 这个代码会将C:\MyApp目录下的所有文件和子目录复制到安装程序的目录中。 5. 编译安装程序 在完成以上步骤后,你需要编译安装程序。在安装程序中,点击“Compile”菜单,选择“Compile”选项。编译完成后,你会得到一个exe文件,这个文件就是你的安装程序。 6. 测试安装程序 你可以在本地测试你的安装程序。双击exe文件,按照安装程序的提示进行安装安装完成后,你可以在安装程序的目录中找到你添加的文件。 7. 发布安装程序 发布你的安装程序非常简单。你只需要将exe文件上传到你的网站或者其他发布平台即可。用户可以下载安装程序并按照提示进行安装。 以上就是将exe打包安装程序的步骤。希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值