场景是我们有一个客户端/服务器应用程序,客户端安装是使用Inno Setup的引导程序,从IP /端口号指定的服务器下载客户端。我们希望能够通过UDP广播检测本地网络上是否有服务器,并且可以编写一个控制台应用程序来执行此操作。问题是,我们如何将信息从控制台应用程序传递给安装程序?
我可以捕获返回码,但这只能是一个int。据我所知,在Inno Setup中读取文件的唯一功能是在预处理器中,因此我们无法读取控制台应用程序在运行时创建的文件。我唯一能想到的是返回一个int,其中前4位是'。's的位置和:在端口之前然后解析出值,这似乎是hackish,flimsy和容易出错,特别是考虑到我并不熟悉用于构造字符串的Inno Setup语法/函数。
有什么建议吗?
答案 0 :(得分:5)
如果要从Inno Setup中的代码解析命令行参数,请使用与此类似的方法。只需从命令行调用安装程序,如下所示:
c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue
然后,您可以在任何需要的地方拨打GetCommandLineParam
:
myVariable := GetCommandLineParam('-myParam');
{ ================================================================== }
{ Allows for standard command line parsing assuming a key/value organization }
function GetCommandlineParam (inParam: String):String;
var
LoopVar : Integer;
BreakLoop : Boolean;
begin
{ Init the variable to known values }
LoopVar :=0;
Result := '';
BreakLoop := False;
{ Loop through the passed in array to find the parameter }
while ( (LoopVar < ParamCount) and
(not BreakLoop) ) do
begin
{ Determine if the looked for parameter is the next value }
if ( (ParamStr(LoopVar) = inParam) and
( (LoopVar+1) < ParamCount )) then
begin
{ Set the return result equal to the next command line parameter }
Result := ParamStr(LoopVar+1);
{ Break the loop }
BreakLoop := True;
end
{ Increment the loop variable }
LoopVar := LoopVar + 1;
end;
end;
希望这会有所帮助......
答案 1 :(得分:3)
不知道如何从命令行加载参数,但您可以使用LoadStringFromFile
加载文件的内容,或GetIniString
从ini文件中读取参数。
更一般地说,请在Inno Setup帮助文件中查找“支持函数参考”。此页面将为您提供所有Inno功能的列表(不包括预处理器)。如果您找不到此页面(如果您只找到有关预处理器的信息),那么您可能正在查找错误的帮助文件。请注意,Inno Setup帮助目录不是那么好,但索引非常好。
命令行参数记录在“设置命令行参数”页面上。您可能可以使用现有参数之一来欺骗Inno,但使用ini文件似乎是最简单的方法。
答案 2 :(得分:2)
答案 3 :(得分:1)
InnoSetup包含一种解释性的Pascal类扩展语言,可以在安装程序运行时使用很多东西。
例如,我知道它可以读取注册表,我相当确定它可以读取文件,至少从某些文件夹中读取。您的控制台模式应用程序可以编写临时文件或删除一个或多个包含安装程序其余部分所需信息的注册表项,并且可以从脚本环境返回到适当的安装脚本。安装程序甚至可以在以后清理临时文件和/或密钥。
答案 4 :(得分:0)
来自Inno设置手册:
{PARAM:PARAMNAME |默认值}
Embeds a command line parameter value.
* ParamName specifies the name of the command line parameter to read from.
* DefaultValue determines the string to embed if the specified command
line parameter does not exist, or its value could not be determined.
示例:
[配置] 的AppId = ... AppName的= {PARAM:exe_name | XYZ} .EXE
更多:www downloadatoz com / manual / in / inno-setup / topic_consts.htm
答案 5 :(得分:0)
上述匿名答案应予以赞成。
我能够通过在脚本中按名称引用参数来将参数传递给我的安装程序:
{param:filePath|abc}
然后在调用安装程序时使用所需格式传递参数值:
MyInnoSetup.exe /filePath=../foo.exe