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

Report installed .NET Framework version during install with Inno Setup

我正在试验 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...', mbInformation, MB_OK);
    end;
end.

您需要从某些 Inno Setup event function, like InitializeSetup.

调用您的代码

有关示例,请参阅 Inno Setup - How can I check system specs before/during installation?


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

既然您已经可以使用 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;