【问题标题】:Setting value of Inno Setup custom page field from command-line从命令行设置 Inno Setup 自定义页面字段的值
【发布时间】:2020-04-09 13:35:06
【问题描述】:

作为安装向导的一部分,我已经配置了以下脚本以询问用户 IP 地址,该地址被写入配置文件,应用程序将参考该配置文件以了解与何处通信。我也想提供机会将此 IP 地址指定为命令行中的参数,以便可以自动进行部署并静默执行。

从我的研究来看,似乎可以添加一个命令行参数,但我很难准确理解如何在我的 Inno 设置中进行设置,然后我如何使这个可选以允许在命令行或通过安装向导。

例如像app1.exe /ipaddress 192.168.0.1这样的东西

抱歉,如果这是一个简单的过程,我是 Inno Setup 的新手,因此我们将不胜感激。

谁能提供任何帮助来帮助我进行此设置?

[Code]

var
  PrimaryServerPage: TInputQueryWizardPage;

function FileReplaceString(ReplaceString: string):boolean;
var
  MyFile : TStrings;
  MyText : string;
begin
  Log('Replacing in file');
  MyFile := TStringList.Create;

  try
    Result := true;

    try
      MyFile.LoadFromFile(ExpandConstant('{app}' + '\providers\win\config.conf'));
      Log('File loaded');
      MyText := MyFile.Text;

      { Only save if text has been changed. }
      if StringChangeEx(MyText, 'REPLACE_WITH_CUSTOMER_IP', ReplaceString, True) > 0 then
      begin;
        Log('IP address inserted');
        MyFile.Text := MyText;
        MyFile.SaveToFile(ExpandConstant('{app}' + '\providers\win\config.conf'));
        Log('File saved');
      end;
    except
      Result := false;
    end;
  finally
    MyFile.Free;
  end;

  Result := True;
end;

procedure InitializeWizard;
begin
  PrimaryServerPage :=
    CreateInputQueryPage(
      wpWelcome, 'Application Server Details', 'Where is installed?',
      'Please specify the IP address or hostname of your ' +
        'Primary Application Server, then click Next.');
  PrimaryServerPage.Add('Primary Application Server IP/Hostname:', False);
end;   

procedure ReplaceIPAddress;
begin
  FileReplaceString(PrimaryServerPage.Values[0]);
end;

【问题讨论】:

    标签: inno-setup


    【解决方案1】:

    读取命令行参数的一种简单方法是使用ExpandConstant function解析{param:} pseudo-constant

    procedure InitializeWizard;
    begin
      PrimaryServerPage :=
        CreateInputQueryPage(
          wpWelcome, 'Application Server Details', 'Where is installed?',
          'Please specify the IP address or hostname of your ' +
            'Primary Application Server, then click Next.');
      PrimaryServerPage.Add('Primary Application Server IP/Hostname:', False);
      PrimaryServerPage.Values[0] := ExpandConstant('{param:ipaddress}');
    end;   
    

    在命令行上,使用以下语法提供值:

    mysetup.exe /ipaddress=192.0.2.0
    

    更多详情请见How can I resolve installer command-line switch value in Inno Setup Pascal Script?


    您是否想自动运行安装程序,在静默模式下跳过页面。对于 WizardSilent function 中的那个查询 ShouldSkipPage event function

    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
      Result := False;
    
      if PageID = PrimaryServerPage.ID then
      begin
        Result := WizardSilent;
      end;
    end;
    

    现在您可以使用此命令行语法来提供值并避免任何提示:

    mysetup.exe /silent /ipaddress=192.0.2.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2013-10-11
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多