您如何使用 Inno Setup 在完成的页面上提示用户阅读指南并 restart/log 离开他们的计算机?

How do you prompt a user to read a guide and restart/log off from their computer on the finished page using Inno Setup?

我正在构建安装程序并希望用户使用单选按钮重新启动。如果用户选择“不,我稍后会重新启动”,我还想包括一个打开用户指南的选项。我目前要求用户打开用户指南的方法是将其放在 [Run] 部分,如下所示:

[Run]
Filename: "{app}\userguide.pdf"; Description: "View the User Guide"; Flags: shellexec runasoriginaluser postinstall nowait unchecked

这非常有效,它甚至可以在默认的 PDF 查看器中打开。但是,每当我尝试包含重启选项时,它都会覆盖用户指南选项并将其完全删除。所以,尝试:

[Code]
function NeedRestart(): Boolean;
begin
    Result := True;
end;

以及:

[Setup]
AlwaysRestart=yes

从某种意义上说,它们包括一个重新启动选项,但它们也覆盖了用户指南按钮。有没有办法制作一个自定义页面,在选中“不,我稍后会重新启动”单选按钮后,将显示打开用户指南的选项?我不太熟悉使用 Inno Setup 和 Delphi/Pascal.

你必须编码。例如,您可以添加自己的复选框以启动用户指南:

[Setup]
AlwaysRestart=yes

[Files]
Source: "userguide.pdf"; DestDir: "{app}"
[Code]

var
  LaunchCheckbox: TCheckbox;

procedure YesNoRadioClicked(Sender: TObject);
begin
  // Disable the user guide checkbox when "restart" is selected
  LaunchCheckbox.Enabled := WizardForm.NoRadio.Checked;
end;

procedure InitializeWizard();
begin
  LaunchCheckbox := TCheckbox.Create(WizardForm.FinishedPage);
  LaunchCheckbox.Caption := 'View the User Guide';
  LaunchCheckbox.Checked := False;
  LaunchCheckbox.Left := WizardForm.YesRadio.Left;
  LaunchCheckbox.Width := WizardForm.YesRadio.Width;
  LaunchCheckbox.Height := ScaleY(LaunchCheckbox.Height);
  LaunchCheckbox.Parent := WizardForm.FinishedPage;
  if (WizardForm.YesRadio.OnClick <> nil) or (WizardForm.NoRadio.OnClick <> nil) then
  begin
    Log('Restart radio button event handler unexpectedly set');
  end
    else
  begin
    WizardForm.YesRadio.OnClick := @YesNoRadioClicked;
    WizardForm.NoRadio.OnClick := @YesNoRadioClicked;
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpFinished then
  begin
    // Adjust to the initial start of restart selection
    YesNoRadioClicked(nil);
    // Only now the restart radio buttons have their definitive vertical position
    LaunchCheckbox.Top :=
      WizardForm.NoRadio.Top + WizardForm.NoRadio.Height + ScaleY(16);
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  ErrorCode: Integer;
begin
  if CurStep = ssDone then
  begin
    if (not WizardSilent) and
       (not WizardForm.YesRadio.Checked) and
       LaunchCheckbox.Checked then
    begin
      Log('Opening user guide');
      ShellExecAsOriginalUser(
        'open', ExpandConstant('{app}\userguide.pdf'), '', '', SW_SHOWNORMAL, 
        ewNoWait, ErrorCode);
    end;
  end;
end;


代码假定 AlwaysRestart。如果重启是有条件的,代码将需要更新以适应 Finished 页面的不同布局,而无需重启。如需完整解决方案,请参阅我的 WinSCP 安装程序:
https://github.com/winscp/winscp/blob/master/deployment/winscpsetup.iss