2017-08-01 116 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 
相關問題