
Inno Setup 安装自动检测 .NET 环境安装解决方案由大眼仔旭(www.dayanzai.me)发布。现在有越来越多的程序是基于 .Net Framework 环境开发的,而这类程序多数依赖 .NET 运行环境。作为在打包分发软件的时候,通过使用 Inno Setup 可以在安装包运行时自动检测电脑上是否安装 .NET 环境。毕竟有些用户是没有安装 .NET 环境,如果直接安装发现无法打开应用程序,就会给用户造成非常不可靠的感觉。
以下的检测方法是由 kybso 发布在 GitHub 社区并共享源代码,这里作一些解释引用:
nno Setup 打包 .Net Framework 到安装包方式脚本:
; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!
#define MyAppName “MyApp”
#define MyAppVersion “1.0”
#define IncludeFramework true
#define IsExternal “”
#define MyAppPublisher “App”
#define MyAppURL “http://www.MyApp.cn”
#define MyAppExeName “MyApp.exe”
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{B0C52F2E-939F-4CE2-89F3-2F0677584526}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=E:\step
Compression=lzma
SolidCompression=yes
#if IncludeFramework
OutputBaseFilename=setup_FW
#else
OutputBaseFilename=Setup
#endif
[Languages]
Name: “chinesesimp”; MessagesFile: “compiler:Default.isl”
[Tasks]
Name: “desktopicon”; Description: “{cm:CreateDesktopIcon}”; GroupDescription: “{cm:AdditionalIcons}”; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Files]
Source: “E:\MyApp\MyApp.exe”; DestDir: “{app}”; Flags: ignoreversion {#IsExternal}
#if IncludeFramework
Source: “D:\开发\dotNetFx40_Full_x86_x64.exe”; DestDir: “{tmp}”; Flags: ignoreversion {#IsExternal}; Check: NeedsFramework
#endif
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”
[Icons]
Name: “{group}\{#MyAppName}”; Filename: “{app}\{#MyAppExeName}”
Name: “{commondesktop}\{#MyAppName}”; Filename: “{app}\{#MyAppExeName}”; Tasks: desktopicon
[Run]
#if IncludeFramework
Filename: {tmp}\dotNetFx40_Full_x86_x64.exe; Parameters: “/q:a /c:””install /l /q”””; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: “Installing .NET Framework if needed”
#endif
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: “-q -machine -remgroup “”{#MyAppName}”””; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: “Setting Program Access Permissions…”
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: “-q -machine -addgroup 1.2 -url “”file://{app}/*”” FullTrust -name “”{#MyAppName}”””; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: “Setting Program Access Permissions…”
[UninstallRun]
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: “-q -machine -remgroup “”{#MyAppName}”””; Flags: skipifdoesntexist runhidden;
[code]
// Indicates whether .NET Framework 2.0 is installed.
function IsDotNET40Detected(): boolean;
var
success: boolean;
install: cardinal;
begin
success := RegQueryDWordValue(HKLM, ‘SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full’, ‘Install’, install);
//success := RegQueryDWordValue(HKLM, ‘SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727’, ‘Install’, install);
Result := success and (install = 1);
end;
//RETURNS OPPOSITE OF IsDotNet20Detected FUNCTION
//Remember this method from the Files section above
function NeedsFramework(): Boolean;
begin
Result := (IsDotNET40Detected = false);
end;
function GetCustomSetupExitCode(): Integer;
begin
if (IsDotNET40Detected = false) then
begin
MsgBox(‘.NET Framework 未能正确安装!’,mbError, MB_OK);
result := -1
end
end;
//卸载程序
function InitializeUninstall(): Boolean;
begin
Result := MsgBox(‘卸载程序:’ #13#13 ‘你真的要卸载该程序?’, mbConfirmation, MB_YESNO) = idYes;
//if Result = False then
// MsgBox(‘InitializeUninstall:’ #13#13 ‘Ok, bye bye.’, mbInformation, MB_OK);
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
ErrorCode: Integer;
begin
case CurUninstallStep of
usUninstall:
begin
//MsgBox(‘卸载程序:’ #13#13 ‘正在卸载…’, mbInformation, MB_OK)
// …insert code to perform pre-uninstall tasks here…
end;
usPostUninstall:
begin
//MsgBox(‘卸载程序:’ #13#13 ‘卸载完成.’, mbInformation, MB_OK);
// …insert code to perform post-uninstall tasks here…
ShellExec(‘open’, ‘http://www.asiafinance.cn’, ”, ”, SW_SHOW, ewNoWait, ErrorCode)
end;
end;
end;
资源:1696.rar
解压密码:www.dayanzai.me
转载请保留出处,谢谢合作~
点击下载(提取码:742b)
点击下载
点击下载
点击下载(提取码:697v)
文章名称:《Inno Setup 安装自动检测 .NET 环境安装解决方案》
文章固定链接:https://www.dayanzai.me/inno-setup-net.html
本站资源仅供个人学习交流,请于下载后 24 小时内删除,不允许用于商业用途,否则法律问题自行承担。
猜你喜欢
- 2023-03-17如何看待 3.5 毫米耳机接口被 Type-C 接口取代?
- 2020-08-20专业的 16 进制编辑工具 WinHex 20.0 中文多语免费版
- 2021-11-29Windows 11:这是获取微软免费操作系统更新的方法
- 2023-05-15入门指南:SSD 硬盘类型与种类详解,让新手秒懂!
- 2025-03-04Windows 弦彩任务栏增强工具 RainbowTaskbar 3.1 + x64 中文多语免费版
相关推荐
- 2024-10-30全能视频转换工具 Leawo Prof. Media 13.0.0.5 中文多语免费版
- 2021-07-02微软正从 Windows 11 中删除的 7 个功能
- 2017-11-05Microsoft Office 365 Business + Professional Plus + Home Premium 原版镜像下载
- 2024-04-30时代变了,平台独占游戏可能已成为过去式
- 2025-01-08开源免费海狸笔记 Beaver Notes 3.8.0 中文多语免费版
发表评论
MORE>>微软应用
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
MORE>>安卓应用
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
MORE>>教程资源
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
MORE>>其它资源
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8