2017-08-01 54 views
1

我已经配置了下面的脚本来要求用户输入IP地址作为安装向导的一部分,该地址被写入应用程序将引用的配置文件知道在哪里沟通。我想提供机会在命令行中将此IP地址指定为参数,以便部署可以自动执行并以静默方式执行。从命令行设置Inno Setup自定义页面字段的值

从我的研究中,似乎可以添加一个命令行参数,但我很难理解如何在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; 

回答

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 functionShouldSkipPage 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