Warm tip: 本文翻译自 stackoverflow.com,查看原文请点击:, please click

其他-使用Inno安装程序启动.NET Core安装程序失败,结果代码为2

(其他 - Starting .NET Core installer using Inno Setup fails with result code 2)

发布于 2020-11-28 10:16:18

我正在尝试使用Inno Setup构建安装程序。我需要为.NET Core框架设置必备安装。到目前为止,我已经能够检测到.NET Core的存在。但是我在执行安装时遇到困难。

这是我到目前为止的代码:

[Files]
Source: "\\shared\path\dotnet-runtime-3.1.10-win-x64.exe"; DestDir: "{tmp}"; \
  Flags: deleteafterinstall; BeforeInstall: InstallFramework; \
  Check: FrameworkIsNotInstalled

[Code]
var 
  CancelWithoutPrompt: boolean;
  InstallValue: Cardinal;

function InitializeSetup(): Boolean;
begin
  CancelWithoutPrompt := false;
  result := true;
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  if CurPageID=wpInstalling then
    Confirm := not CancelWithoutPrompt;
end;
             
function FrameworkIsNotInstalled: Boolean;
begin
  Result := not RegQueryDWordValue(HKEY_LOCAL_MACHINE, 
    'SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App', 
    '3.1.10', InstallValue) or (InstallValue <> 1)
end;

procedure InstallFramework;
var
  StatusText: string;
  ResultCode: Integer;
begin
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := 'Installing .net core framework...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  try
    if not Exec(ExpandConstant('{tmp}\dotnet-runtime-3.1.10-win-x64.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then     
    begin
      // you can interact with the user that the installation failed
      MsgBox('.NET Core installation failed with code: ' + IntToStr(ResultCode) + '.',
        mbError, MB_OK);
      CancelWithoutPrompt := true;
      WizardForm.Close;       
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal;
  end;
end;

我从安装中得到结果代码2的响应,任何人都可以启发我代码2错误是什么?还是以任何方式我可以提取有关错误信息的更多详细信息?我尝试使用空参数,并尝试在Internet上搜索Code 2错误信息,但还是没有运气。我曾经尝试过Shellexec并返回相同的结果

直接使用.net exe进行的安装在本地运行正常

任何帮助或信息将不胜感激=)

Questioner
ragk
Viewed
11
Martin Prikryl 2020-11-30 15:05:51

你尝试先运行,dotnet-runtime-3.1.10-win-x64.exe然后再实际“安装”{tmp}

BeforeInstall: InstallFramework

你必须使用AfterInstall参数

AfterInstall: InstallFramework