如果将命令行开关传递给基于Inno Setup的安装程序,则安装文件 [英] Install files if command-line switch is passed to Inno Setup based installer
问题描述
我想知道,是否有一种方法可以为/VERYSILENT
模式向基于Inno Setup的安装程序中添加一些命令行参数,例如,如果我进行了以下检查:
I want to know, if there is a way to add some command line parameters to Inno Setup based installer for /VERYSILENT
mode, if for example I have theses checks:
Source: "{app}\Portable-File.exe"; DestDir: "{app}"; MinVersion: 0.0,5.0; Check: install1;
Source: "{app}\Installer-File.exe"; DestDir: "{app}"; MinVersion: 0.0,5.0; Check: porta1;
在我的两个示例检查中,我有以下几行内容:
And I have these lines based in my two examples checks:
"MyProgram.exe" /VERYSILENT /install1 /EN
"MyProgram.exe" /VERYSILENT /porta1 /EN
推荐答案
实现install1
和porta1
函数,例如:
function HasCommandLineSwitch(Name: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
begin
if CompareText(ParamStr(I), '/' + Name) = 0 then
begin
Result := True;
Break;
end;
end;
end;
function install1: Boolean;
begin
Result := HasCommandLineSwitch('install1');
end;
function porta1: Boolean;
begin
Result := HasCommandLineSwitch('porta1');
end;
您实际上可以直接在Check
参数中使用HasCommandLineSwitch
:
You can actually use the HasCommandLineSwitch
directly in the Check
parameter:
[Files]
Source: "Portable-File.exe"; DestDir: "{app}"; Check: HasCommandLineSwitch('install1')
Source: "Installer-File.exe"; DestDir: "{app}"; Check: HasCommandLineSwitch('porta1')
尽管我认为您的install1
和porta1
函数实际上不仅仅可以调用HasCommandLineSwitch
来做更多的事情,所以这可能不适用于您.
Though I assume that your install1
and porta1
function will actually do more than just call HasCommandLineSwitch
, so this is probably not applicable to you.
实际上,据我所知,您真正想要做的是与install1
和porta1
相对应的复选框,是在安装程序启动时,如果指定了开关,则请选中这些复选框. .这样,即使未与/verysilent
结合使用,也可以使用/install1
和/porta1
设置默认值.即使用户实际上永远不会看到复选框(即使不可见,它们仍然存在),它仍然可以在/verysilent
模式下使用.
Actually, as I know that you have checkboxes that correspond to install1
and porta1
, what you really want to do, is to check those checkboxes, when the installer is starting, if the switches are specified. This way you can use /install1
and /porta1
to set default values, even if not used in combination with /verysilent
. And it will still work even in the /verysilent
mode, even though the user will actually never see the checkboxes (they are still present, even though not visible)
install1 := TNewRadioButton.Create(WizardForm);
install1.Checked := HasCommandLineSwitch('install1');
porta1 := TNewRadioButton.Create(WizardForm);
porta1.Checked := HasCommandLineSwitch('porta1');
然后保留install1
和porta1
函数以返回复选框的状态,如 Inno Setup Set Uninstallable所示基于自定义复选框值的指令.
And you keep your install1
and porta1
function to return the state of the checkboxes, as seen in Inno Setup Set Uninstallable directive based on custom checkbox value.
这篇关于如果将命令行开关传递给基于Inno Setup的安装程序,则安装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!