使用 Inno Setup 安装期间报告已安装的 .NET Framework 版本

问题描述

我正在试验 Inno Setup,为创建安装程序做准备。我的第一次尝试是向用户报告当前安装了哪个 .NET Framework。我想出了以下脚本,它安装了一个令牌 exe,但它没有显示我想要显示已安装的框架版本的消息框。

[Setup]
AppName=NETFramework_Test
AppVersion=1.0.0
DefaultDirName=c:\al\NetFWTest\test
WizardStyle=modern
OutputDir=c:\al\NetFWTest

[Files]
Source: "c:\al\computer\miscsmallapps\tmpdir\tmpdir.exe"; DestDir: "{app}";
[Code]
var
  VersionNum: cardinal;

begin
  if RegQueryDWordValue(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full','Version',VersionNum) then
    begin
      MsgBox('The installed .NET Framework version:' + IntToStr(VersionNum),mbinformation,MB_OK);
    end
  else
    begin
      MsgBox('Error reading the Registry...',MB_OK);
    end;
end.

解决方法

当您已经可以使用 IsDotNetInstalled 时,为什么要手动执行此操作?

例如:

[Code]
// InitializeSetup is called when the setup is starting.
function InitializeSetup(): Boolean;
begin
  Result := True;
  if not IsDotNetInstalled(net462,0) then
  begin
    MsgBox('The required .NET Framework version 4.6.2 is not installed.',mbError,MB_OK)
    Result := False;
  end;
end;
,

您需要从某个 Inno Setup event function,like InitializeSetup 调用您的代码。

示例见Inno Setup - How can I check system specs before/during installation?


另外,Version 的值是字符串,所以你需要使用 RegQueryStringValue