在升级/重新安装的情况下,有没有办法丢弃在命令行上传递给安装程序的 /TYPE/COMPONENTS 参数值,而是使用以前使用的值?
我可以从注册表中读取之前使用的值(或者,假设文件没有被手动更改,则可以根据文件的存在来确定详细信息)

我已阅读以下线程,可以在 UI 模式下禁用“选择组件”页面

  • Inno Setup Skip "Select Components" page when /Type command-line parameter is specified
  • InnoSetup: Disable components page on upgrade

  • 但是,如果上述参数是从命令行传递的,它们似乎会覆盖默认值。

    最佳答案

    你不能丢弃它们。
    您可以做的是检查是否提供了这些参数以及它们是否:

  • 在没有它们的情况下重新启动安装程序(如下所示),或
  • 从注册表中读取先前选择的类型和组件,并相应地重新设置控件。

  • 在没有 /TYPE=/COMPONENTS= 的情况下重新启动安装程序
    const
      UninstallKey =
        'Software\Microsoft\Windows\CurrentVersion\Uninstall\' +
        '{#SetupSetting("AppId")}_is1';
    
    function IsUpgrade: Boolean;
    var
      Value: string;
    begin
      Result :=
        (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or
         RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and
        (Value <> '');
    end;
    
    function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
      lpParameters: string; lpDirectory: string; nShowCmd: Integer): THandle;
      external 'ShellExecuteW@shell32.dll stdcall';
    
    function InitializeSetup(): Boolean;
    var
      Params, S: string;
      Relaunch: Boolean;
      I, RetVal: Integer;
    begin
      Result := True;
    
      if IsUpgrade then
      begin
        Relaunch := False;
        // Collect current instance parameters
        for I := 1 to ParamCount do
        begin
          S := ParamStr(I);
          if (CompareText(Copy(S, 1, 7), '/TYPES=') = 0) or
             (CompareText(Copy(S, 1, 12), '/COMPONENTS=') = 0) then
          begin
            Log(Format('Will re-launch due to %s', [S]));
            Relaunch := True;
          end
            else
          begin
            // Unique log file name for the child instance
            if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then
            begin
              S := S + '-sub';
            end;
            // Do not pass our /SL5 switch
            // This should not be needed since Inno Setup 6.2,
            // see https://groups.google.com/g/innosetup/c/pDSbgD8nbxI
            if CompareText(Copy(S, 1, 5), '/SL5=') <> 0 then
            begin
              Params := Params + AddQuotes(S) + ' ';
            end;
          end;
        end;
    
        if not Relaunch then
        begin
          Log('No need to re-launch');
        end
          else
        begin
         Log(Format('Re-launching setup with parameters [%s]', [Params]));
          RetVal :=
            ShellExecute(0, '', ExpandConstant('{srcexe}'), Params, '', SW_SHOW);
          Log(Format('Re-launching setup returned [%d]', [RetVal]));
          Result := (RetVal > 32);
          // if re-launching of this setup succeeded, then...
          if Result then
          begin
            Log('Re-launching succeeded');
            // exit this setup instance
            Result := False;
          end
            else
          begin
            Log(Format('Elevation failed [%s]', [SysErrorMessage(RetVal)]));
          end;
        end;
      end;
    end;
    
    该代码适用于 Inno Setup 的 Unicode 版本。
    可以进一步改进代码以保持主安装程序等待子安装程序完成。什么时候会有所作为,特别是如果安装程序是由某个自动部署过程执行的。

    关于inno-setup - 升级时丢弃/TYPE 和/COMPONENTS 参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45273328/

    10-13 02:46