从命令行应用程序将字符串值传递给 Inno Setup
场景是,我们有一个客户端/服务器应用程序,客户端安装是使用 Inno Setup 的引导程序,它从 IP/端口号指定的服务器下载客户端。 我们希望能够通过 UDP 广播检测本地网络上是否有服务器,并可以编写一个控制台应用程序来执行此操作。 问题是,我们如何将信息从控制台应用程序传递到安装程序?
我可以捕获返回码,但它只能是一个 int。 据我所知,Inno Setup 中读取文件的唯一功能是在预处理器中,因此我们无法读取控制台应用程序在运行时创建的文件。 我唯一能想到的就是返回一个 int ,其中前 4 位数字是端口之前 '.' 和 : 的位置,然后解析出该值,这看起来很hackish、脆弱且容易出错,特别是考虑到我不太熟悉用于构造字符串的 Inno Setup 语法/函数。
有什么建议么?
The scenario is that we have a client/server app with the client install being a bootstrapper using Inno Setup that downloads the client from the server specified by IP/Port number. We'd like to be able to detect if there is a server on the local network via UDP broadcasting, and can write a console app that does that. Problem is, how do we pass the information from the console app to the installer?
I can capture the return code, but that can only be an int. As far as I can tell, the only functions to read file in Inno Setup is in the preprocessor so we can't read a file created at runtime by the console app. The only thing I can think of is to return an int where the first 4 digits are the position of the '.'s and : before the port and then parse out the value, which seems hackish, flimsy, and error prone, especially considering I'm not intimately familiar with Inno Setup syntax/functions for constructing a string.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想从 Inno Setup 中的代码解析命令行参数,请使用与此类似的方法。 只需从命令行调用安装程序,如下所示:
然后您可以在任何需要的地方调用
GetCommandLineParam
:If you want to parse command line arguments from code in Inno Setup, then use a method similar to this. Just call the installer from the command line as follows:
Then you can call the
GetCommandLineParam
like this wherever you need it:不知道如何从命令行加载参数,但您可以使用
LoadStringFromFile
加载文件内容或GetIniString
从 ini 文件读取参数。更一般地说,在 Inno Setup 帮助文件中查找“支持功能参考”。 此页面将为您提供所有 Inno 函数的列表(不包括预处理器)。 如果您找不到此页面(如果您只找到有关预处理器的信息),那么您可能正在查找错误的帮助文件。 请注意,Inno Setup 帮助的目录不是那么好,但索引非常好。
命令行参数记录在“设置命令行参数”页面上。 您可能可以通过使用现有参数之一来欺骗 Inno,但使用 ini 文件似乎是最直接的方法。
Don't know how to load a parameter from the command line, but you can use
LoadStringFromFile
to load the contents of a file orGetIniString
to read a parameter from an ini file.More generally, look for "Support Functions Reference" in the Inno Setup Help file. This page will give you a list of all the Inno functions (not including the preprocessor). If you can't find this page (if you only find information about the preprocessor) then you may be looking in the wrong helpfile. Note that the Inno Setup Help table of contents isn't all that great but the index is very good.
Command line parameters are documented on the page "Setup Command Line Parameters". It's possible that you might be able to trick Inno by using one of the existing parameters, but using an ini file seems like it would be the most straightforward approach.
上面的匿名回答应该被点赞。
我只需在脚本中按名称引用参数即可将参数传递给安装程序:
然后在调用安装程序时使用所需的格式传递参数值:
The above anonymous answer should be upvoted.
I was able to pass an argument to my installer by just referring to the parameter by name in the script:
And then when calling the installer pass the parameter value using the required format:
InnoSetup 包含一种类似 Pascal 的解释型扩展语言,可以在安装程序运行时用于很多事情。
例如,我知道它可以读取注册表,并且我相当确定它可以读取文件,至少可以从某些文件夹中读取文件。 您的控制台模式应用程序可以写入临时文件或删除一个或多个包含安装程序其余部分所需信息的注册表项,并且可以从脚本环境返回到正确的安装脚本中。 安装程序甚至可以稍后清理临时文件和/或密钥。
InnoSetup includes an interpreted Pascal-like extension language that can be used to a lot of things during the installer's runtime.
For instance, I know it can read the registry, and I am fairly sure it can read files, at least from some folders. Your console-mode app could write a temp file or drop one or more registry keys containing the info needed in the rest of the installer, and that can be returned from the scripting environment into the setup script proper. The installer could even clean up the temp file and/or keys later.
来自 Inno Setup 手册:
{param:ParamName|DefaultValue}
示例:
[Setup]
应用程序 ID=...
AppName={param:exe_name|xyz}.exe
更多:www downloadatoz com/manual/in/inno-setup/topic_consts.htm
From the Inno Setup manual:
{param:ParamName|DefaultValue}
Example:
[Setup]
AppId=...
AppName={param:exe_name|xyz}.exe
More: www downloadatoz com/manual/in/inno-setup/topic_consts.htm