Inno Setup conditional restart based on result of executable call

后端 未结 1 988
悲&欢浪女
悲&欢浪女 2021-01-07 04:43

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

相关标签:
1条回答
  • 2021-01-07 05:44

    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;
    
    0 讨论(0)
提交回复
热议问题