Inno Setup根据可执行调用的结果有条件地重新启动 [英] Inno Setup conditional restart based on result of executable call

查看:291
本文介绍了Inno Setup根据可执行调用的结果有条件地重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Inno设置"脚本用于安装驱动程序.在步骤ssInstall中复制此文件后,它将运行我的InstallDriver.exe.

My Inno Setup script is used to install a driver. It runs my InstallDriver.exe after this file was copied during step ssInstall.

在某些情况下,我需要根据InstallDriver.exe返回的值要求用户重新启动.

I need to ask the user to restart in some cases according to the value returned by InstallDriver.exe.

这意味着我无法将InstallDriver.exe放在[Run]部分中,因为无法监视其返回值.

This means that I cannot put InstallDriver.exe in section [Run] because there's no way to monitor it's return value.

因此我将其放在函数CurStepChanged()中,如下所示:

So I put it in function CurStepChanged() as follows:

procedure CurStepChanged(CurStep: TSetupStep);
var
  TmpFileName, ExecStdout, msg: string;
  ResultCode: Integer;
begin
  if  (CurStep=ssPostInstall)  then
  begin 
    Log('CurStepChanged(ssPostInstall)');
    TmpFileName := ExpandConstant('{app}') + '\InstallDriver.exe';
    if Exec(TmpFileName, 'I', '',  SW_HIDE, ewWaitUntilTerminated, ResultCode) then .......

但是,在此阶段,我找不到使脚本重新启动的方法.

However, I can't find a way to make my script restart at this stage.

我想到了使用功能NeedRestart()来监视驱动程序安装程序的输出,但是在此过程的早期被调用. 从NeedRestart()中调用驱动程序安装程序有意义吗?

I thought of using function NeedRestart() to monitor the output of the driver installer, but it is called earlier in the process. Does it make sense to call the driver installer from within NeedRestart()?

推荐答案

NeedRestart看起来不适合安装任何内容.但这是可行的,因为它只被调用了一次.不过,您可能希望以某种方式显示进度,因为在调用NeedRestart时向导表单几乎为空.

NeedRestart does not look like the right place to install anything. But it would work, as it's fortunately called only once. You will probably want to present a progress somehow though, as the wizard form is almost empty during a call to NeedRestart.

一种替代方法是使用 AfterInstall参数 >或驱动程序二进制文件本身(以更高版本为准).

An alternative is to use AfterInstall parameter of the InstallDriver.exe or the driver binary itself (whichever is installed later).

#define InstallDriverName "InstallDriver.exe"

[Files]
Source: "driver.sys"; DestDir: ".."
Source: "{#InstallDriverName}"; DestDir: "{app}"; AfterInstall: InstallDriver

[Code]
var
  NeedRestartFlag: Boolean;

const
  NeedRestartResultCode = 1;

procedure InstallDriver();
var
  InstallDriverPath: string;
  ResultCode: Integer;
begin
  Log('Installing driver');
  InstallDriverPath := ExpandConstant('{app}') + '\{#InstallDriverName}';
  if not Exec(InstallDriverPath, 'I', '',  SW_HIDE, ewWaitUntilTerminated, ResultCode) then
  begin
    Log('Failed to execute driver installation');
  end
    else
  begin
    Log(Format('Driver installation finished with code %d', [ResultCode]))
    if ResultCode = NeedRestartResultCode then
    begin
      Log('Need to restart to finish driver installation');
      NeedRestartFlag := True;
    end;
  end;
end;

function NeedRestart(): Boolean;
begin
  if NeedRestartFlag then
  begin
    Log('Need restart');
    Result := True;
  end
    else
  begin
    Log('Do not need restart');
    Result := False;
  end;
end;

这篇关于Inno Setup根据可执行调用的结果有条件地重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆