inno setup 检测.net环境

inno setup 检查当前 .NET Framework 环境并安装


大约分为两种方式

  1. 安装过程中连接官网下载地址 下载到本地 进行安装(看网络带宽 微软官网国内有时不灵)
  2. 将脱机安装文件和安装包打包在一起 安装时直接读取本地文件进行安装(安装包文件会很大 毕竟.net环境也在里面)

参考网址
1. 微软官网:.NET Framework 部署指南(针对开发人员)
2. 官网inno setup 打包教程: Installing .NET Framework 4.5 automatically with Inno Setup
3. 特别实在的一篇教程: inno setup安装制作软件详细使用步骤(含检测net版本环境)
4. 解决打包文件夹问题:InnoSetup 打包文件夹的解决方案

在这里插入图片描述

主要是Code 部分怎么写

Code


个人总结拼接出来的code 检查版本的方法就是去注册表去找
[Code]
// 'Software\Microsoft\NET Framework Setup\NDP\v4\Full'   当前安装的.net 环境地址
//  461814  当前 .net 版本           对照 https://docs.microsoft.com/zh-cn/dotnet/framework/deployment/deployment-guide-for-developers  
// 判断是否有安装.net 4.7.2 运行环境
function Framework472IsNotInstalled(): Boolean;
var
  bSuccess: Boolean;
  regVersion: Cardinal;
begin
  Result := True;
  // 检查版本
  bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', regVersion);
  if (True = bSuccess) and (regVersion >= 461814) then begin
    Result := False;
  end;
end;

// 下面两个方法 组合调用  安装.net 环境
procedure InstallFramework;
var
  StatusText: string;
  ResultCode: Integer;
begin
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := '正在安装 .NET Framework 4.7.2. 可能需要几分钟的时间...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  try
     //打包在安装包里面的   ndp472.exe  .net 环境安装程序
    if not Exec(ExpandConstant('{tmp}\ndp472.exe'), '/passive /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      MsgBox('.NET 安装失败,请联系管理员,代码: ' + IntToStr(ResultCode) + '.', mbError, MB_OK);
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal; 
    DeleteFile(ExpandConstant('{tmp}\ndp472.exe'));
  end;
end;

// 该过程提供用户完成预安装和安装之后的任务,更多的是提供了安装过程中的状态。           相当于钩子函数
//if CurStep=ssinstall then
//   MsgBox('准备写入文件了', mbInformation, MB_OK);
// if CurStep=ssPostinstall then
//     MsgBox('文件复制完成', mbInformation, MB_OK);        
// if CurStep=ssDone then
//     MsgBox('软件成功安装', mbInformation, MB_OK);
procedure CurStepChanged(CurStep: TSetupStep);
begin
  case CurStep of
    ssPostInstall:
      begin
        if Framework472IsNotInstalled() then
        begin
          InstallFramework();
        end;
      end;
  end;
end;

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"; LicenseFile: "compiler:License\chinesesimp.txt"
Name: "chinesetra"; MessagesFile: "compiler:Languages\ChineseTraditional.isl"; LicenseFile: "compiler:License\chinesetra.txt"
Name: "english"; MessagesFile: "compiler:Languages\English.isl";LicenseFile: "compiler:License\english.txt"

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

[Files]
Source: "..所在路径..\Debug\ndp472.exe"; DestDir: "{app}"; Flags: ignoreversion

微软官网演示

[Code]
function Framework47IsNotInstalled(): Boolean;
var
  bSuccess: Boolean;
  regVersion: Cardinal;
begin
  Result := True;
  bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', regVersion);
  if (True = bSuccess) and (regVersion >= 378389) then begin
    Result := False;
  end;
end;

procedure InitializeWizard;
begin
  if Framework47IsNotInstalled() then
  begin
    idpAddFile('https://dotnet.microsoft.com/download/dotnet-framework/net472', ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
    idpDownloadAfter(wpReady);
  end;
end;

procedure InstallFramework;
var
  StatusText: string;
  ResultCode: Integer;
begin
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := 'Installing .NET Framework 4.7.2. This might take a few minutes...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  try
    if not Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.', mbError, MB_OK);
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal;
DeleteFile(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  case CurStep of
    ssPostInstall:
      begin
        if Framework47IsNotInstalled() then
        begin
          InstallFramework();
        end;
      end;
  end;
end;

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值