是否可以使用 Inno Setup 接受自定义命令行参数
我正在使用 Inno Setup 准备安装程序。但我想添加一个额外的自定义(没有可用参数)命令行参数,并希望获取参数的值,例如:
setup.exe /do something
检查是否给出了 /do
,然后获取某物的价值。是否可以?我该怎么做?
I am preparing an installer with Inno Setup. But I'd like to add an additional custom (none of the available parameters) command line parameters and would like to get the value of the parameter, like:
setup.exe /do something
Check if /do
is given, then get the value of something. Is it possible? How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用 InnoSetup 5.5.5(或许还有其他版本),只需将您想要的任何内容作为参数传递,以
/
为前缀并在 myApp.iss 中:
|waggle
提供如果没有参数匹配则使用默认值。 Inno 设置不区分大小写。这是处理命令行选项的一种特别好的方法:它们突然出现。我希望有一种巧妙的方法让用户知道安装程序关心哪些命令行参数。顺便说一句,这使得 @knguyen 和 @steve-dunn 的答案都有些多余。实用函数的作用与内置
{param: }
语法的作用完全相同。With InnoSetup 5.5.5 (and perhaps other versions), just pass whatever you want as a parameter, prefixed by a
/
and in your myApp.iss:
The
|waggle
provides a default value if no parameter matches. Inno setup is not case sensitive. This is a particularly nice way to handle command line options: They just spring into existence. I wish there was as slick a way to let users know what command line parameters the installer cares about.BTW, this makes both @knguyen's and @steve-dunn's answers somewhat redundant. The utility functions do exactly what the built-in
{param: }
syntax does.Inno Setup 直接支持使用
{param}
常量。您可以直接在节中使用常量,尽管这种用途非常有限。
示例:
您更有可能希望在 Pascal 脚本 中使用开关。
如果您的开关具有语法
/Name=Value
,则读取其值的最简单方法是使用ExpandConstant
函数。例如:
如果您想使用开关值来切换部分中的条目,您可以使用 < code>Check 参数 和辅助函数,例如:
具有讽刺意味的是,仅检查 switch 是否存在(没有值)会更困难。
用户可以使用@TLama对在Inno Setup中传递条件参数的回答中的函数
CmdLineParamExists
。显然,您可以在 Pascal Script 中使用该函数:
但您甚至可以在部分中使用它,最典型的是使用
检查
参数:相关问题:
将用户定义的命令行参数添加到 /?窗口
Inno Setup directly supports switches with syntax
/Name=Value
using{param}
constant.You can use the constant directly in sections, though this use is quite limited.
An example:
You will more likely want to use switches in Pascal Script.
If your switch has the syntax
/Name=Value
, the easiest way to read its value is usingExpandConstant
function.For example:
If you want to use a switch value to toggle entries in sections, you can use
Check
parameter and a auxiliary function, like:Ironically it is more difficult to check for a mere presence of switch (without a value).
Use can use a function
CmdLineParamExists
from @TLama's answer to Passing conditional parameter in Inno Setup.You can obviously use the function in Pascal Script:
But you can even use it in sections, most typically using
Check
parameter:A related problem:
Add user defined command line parameters to /? window
根据 @DanLocks 的回答,
{param:*ParamName|DefaultValue*}
常量是记录在常量页面底部附近:http://www.jrsoftware.org /ishelp/index.php?topic=consts
我发现它对于选择性抑制许可证页面非常方便。以下是我需要添加的所有内容(使用 Inno Setup 5.5.6(a)):
Further to @DanLocks' answer, the
{param:*ParamName|DefaultValue*}
constant is documented near the bottom of the Constants page:http://www.jrsoftware.org/ishelp/index.php?topic=consts
I found it quite handy for optionally suppressing the license page. Here is all I needed to add (using Inno Setup 5.5.6(a)):
如果您想从 inno 中的代码解析命令行参数,请使用与此类似的方法。只需从命令行调用 inno 脚本,如下所示:
然后您可以在任何需要的地方调用 GetCommandLineParam :
If you want to parse command line arguments from code in inno, then use a method similar to this. Just call the inno script from the command line as follows:
Then you can call the GetCommandLineParam like this wherever you need it:
这是我写的函数,是对 Steven Dunn 答案的改进。您可以将其用作:
This is the function I wrote, which is an improvement of Steven Dunn's answer. You can use it as:
是的,可以,您可以使用
ParamStr
函数用于访问所有命令行参数。ParamCount
函数将为您提供数字命令行参数。另一种可能性是使用
GetCmdTail
Yes it is possible, you can use the
ParamStr
function in PascalScript to access all the commandline parameters. TheParamCount
function will give you the number of commandline parameters.Another possibility is to use
GetCmdTail
您可以将参数传递给安装程序脚本。安装 Inno 安装预处理器 并阅读有关传递自定义命令行参数的文档。
You can pass parameters to your installer scripts. Install the Inno Setup Preprocessor and read the documentation on passing custom command-line parameters.
响应:
“使用 InnoSetup 5.5.5(或许还有其他版本),只需传递您想要的任何内容作为参数,并以 / 为前缀”
“@NickG,是的,您可以通过 ExpandConstant 函数扩展每个常量”
PS:我本来可以直接添加评论,但显然我没有足够的“声誉”
In response to:
"With InnoSetup 5.5.5 (and perhaps other versions), just pass whatever you want as a parameter, prefixed by a /"
"@NickG, yes, every constant you can expand by the ExpandConstant function"
PS: I would have added a comment directly but apparently I dont have enough "reputation"
我对knguyen的答案做了一些修改。现在它不区分大小写(您可以编写控制台 /myParam 或 /MYPARAM)并且它可以接受默认值。另外,当您收到比预期更大的参数时,我还修复了这种情况(例如: /myParamOther="parameterValue" 代替 /myParam="parameterValue"。现在 myParamOther 不匹配)。
I've modified a little bit knguyen's answer. Now it's case insensitive (you can write en console /myParam or /MYPARAM) and it can accept default value. Also I fixed the case when you receive larger parameter then expected (for ex: /myParamOther="parameterValue" in place of /myParam="parameterValue". Now myParamOther doesn't match).
我找到了答案:GetCmdTail。
I found the answer: GetCmdTail.