2009-03-04 74 views
2

该方案是我们有一个客户端/服务器应用程序,客户端安装是使用Inno Setup从客户端从IP /端口号指定的服务器下载客户端的引导程序。我们希望能够通过UDP广播检测本地网络上是否有服务器,并且可以编写一个控制台应用程序来实现这一点。问题是,我们如何将控制台应用程序的信息传递给安装程序?从命令行将字符串值传递给Inno Setup应用程序

我可以捕获返回代码,但那只能是int。据我所知,Inno Setup中唯一读取文件的函数是在预处理程序中,所以我们无法读取由控制台应用程序在运行时创建的文件。我能想到的唯一的事情就是返回一个int,其中前4位数字是'。'和:在端口之前的位置,然后解析出这个值,这看起来像是hackish,flimsy和容易出错的,尤其是考虑到我并不熟悉Inno Setup语法/构造字符串的函数。

有什么建议吗?

回答

3

不知道如何从命令行加载参数,但可以使用LoadStringFromFile加载文件的内容或GetIniString以从ini文件读取参数。

更一般地,在Inno Setup帮助文件中查找“Support Functions Reference”。本页面将给你所有Inno功能(不包括预处理器)的列表。如果你找不到这个页面(如果你只能找到关于预处理器的信息),那么你可能会看到错误的帮助文件。请注意,Inno Setup Help目录并不是那么好,但索引非常好。

命令行参数记录在页面“Setup Command Line Parameters”中。有可能你可以通过使用现有的参数来欺骗Inno,但是使用ini文件看起来好像是最直接的方法。

+0

在我安装的版本中,至少它看起来像预处理器帮助被合并到主帮助文件中,尽管我记得它们在旧版Inno中是分开的,并且在搜索索引时很难分辨哪个是ISPP,而不是 – Davy8 2009-03-05 14:20:16

1

InnoSetup包含一个解释的类似Pascal的扩展语言,它可以在安装程序的运行时用于很多事情。

例如,我知道它可以读取注册表,我确信它可以读取文件,至少从某些文件夹中读取文件。您的控制台模式应用程序可以编写临时文件或删除一个或多个包含安装程序其余部分中所需信息的注册表项,并且可以从脚本环境返回适当的安装脚本。安装程序甚至可以在稍后清理临时文件和/或密钥。

0

从创新安装手册:

{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

+0

这是为了在启动安装过程时传递命令行参数。安装程序执行一个命令行应用程序,需要将值返回到当前正在运行的安装程序。 – Davy8 2009-05-20 18:37:57

4

如果您想从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; 

希望这有助于..

+0

我认为循环时代码会丢失2'等号'符号。它应该阅读: *而((LoopVar <= ParamCount)和(非BreakLoop))做 和 *而((LoopVar <= ParamCount)和(非BreakLoop))做 – 2016-01-11 12:15:02

0

上面的匿名答案应该是upvoted。

我能够通过单指参数的名字在脚本中的参数传递给我的安装程序:

{param:filePath|abc} 

,然后调用安装使用所需格式传递参数值时:

MyInnoSetup.exe /filePath=../foo.exe 
相关问题