Setting value of Inno Setup custom page field from command-line

烈酒焚心 提交于 2019-12-23 02:27:01

问题


I have configured the below script to ask the user for an IP address as part of the install wizard, this address gets written to a config file which the application will reference to know where to communicate with. I would like to offer the opportunity to specify this IP address as a parameter in the command line as well so that deployment can be automated and performed silently.

From my research, it seems to be possible to add a command line parameter but I am struggling to understand exactly how to set this up within my Inno setup and then how I can make this optional to allow it to be specified on the command line or through the install wizard.

For example something like app1.exe /ipaddress 192.168.0.1

Apologies if this is an easy process, I am new to Inno Setup so any help would be appreciated.

Can anyone offer any assistance to help me get this 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;

回答1:


One easy way to read command-line parameter is to resolve {param:} pseudo-constant using ExpandConstant function:

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;   

On command-line, use this syntax to provide the value:

mysetup.exe /ipaddress=192.0.2.0

For more details, see How can I resolve installer command-line switch value in Inno Setup Pascal Script?


Shall you want to run the installer automatically, make the page be skipped in the silent mode. For that query WizardSilent function in ShouldSkipPage event function:

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;

  if PageID = PrimaryServerPage.ID then
  begin
    Result := WizardSilent;
  end;
end;

Now you can use this command-line syntax to provide the value and avoid any prompts:

mysetup.exe /silent /ipaddress=192.0.2.0


来源:https://stackoverflow.com/questions/45442551/setting-value-of-inno-setup-custom-page-field-from-command-line

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