Inno Setup conditional restart based on result of executable call

寵の児 提交于 2019-11-30 20:48:08

问题


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

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

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

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.

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()?


回答1:


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.


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;


来源:https://stackoverflow.com/questions/34029065/inno-setup-conditional-restart-based-on-result-of-executable-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!