从命令行设置Inno Setup自定义页面字段的值 [英] Setting value of Inno Setup custom page field from command-line
问题描述
我已经配置了以下脚本,作为安装向导的一部分,要求用户提供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;
读取命令行参数的一种简单方法是解析 ExpandConstant
函数:
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
有关更多详细信息,请参见如何在Inno Setup Pascal脚本中解析安装程序的命令行开关值? >
如果要自动运行安装程序,请在静默模式下跳过页面.对于该查询,WizardSilent
函数 /jrsoftware.org/ishelp/index.php?topic=scriptevents&anchor=ShouldSkipPage"rel =" nofollow noreferrer> ShouldSkipPage
事件函数:
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
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;
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
这篇关于从命令行设置Inno Setup自定义页面字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!