Inno setup 如何根据Inno设置中选择的组件设置启动程序?

Inno setup 如何根据Inno设置中选择的组件设置启动程序?,inno-setup,launching-application,Inno Setup,Launching Application,我使用Inno Setup设计了我的安装程序,以显示2个组件供用户选择。根据他/她的选择,最后的“完成”页面将显示“启动程序”复选框。如果选择了两个组件,则复选框的默认值为false 到目前为止,一切顺利 现在,我希望如果用户只选择其中一个组件进行安装,那么复选框的默认值应该为true 以下是安装程序的组件和运行部分 [Components] Name: "Component1"; Description: "Component1"; Types: full; Name: "Component2

我使用Inno Setup设计了我的安装程序,以显示2个组件供用户选择。根据他/她的选择,最后的“完成”页面将显示“启动程序”复选框。如果选择了两个组件,则复选框的默认值为false

到目前为止,一切顺利

现在,我希望如果用户只选择其中一个组件进行安装,那么复选框的默认值应该为true

以下是安装程序的组件和运行部分

[Components]
Name: "Component1"; Description: "Component1"; Types: full;
Name: "Component2"; Description: "Component2"; Types: full custom; 

[Run]
Filename: "{localappdata}\MyInstaller\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked; Components:Component1;
Filename: "{localappdata}\MyInstaller\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(TestAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked; Components:Component2
我知道我想要的东西需要一些脚本来完成。我不知道该怎么办

请参考。

该参数允许您使用布尔表达式运算符,因此对于您的情况,您可以编写两对条目,其中一对用于未选中复选框,另一对用于选中。您需要的其余部分是编写一个表达式:

[Components]
Name: "Component1"; Description: "Component1";
Name: "Component2"; Description: "Component2";

[Run]
; this is the entry pair for unchecked check box; it is shown if both components
; are selected
Filename: "{app}\MyProg1.exe"; Flags: nowait postinstall skipifsilent unchecked; Components: Component1 and Component2;
Filename: "{app}\MyProg2.exe"; Flags: nowait postinstall skipifsilent unchecked; Components: Component1 and Component2;
; this is the entry pair for checked check box; it is shown only when the given
; component is selected and the other not
Filename: "{app}\MyProg1.exe"; Flags: nowait postinstall skipifsilent; Components: Component1 and not Component2;
Filename: "{app}\MyProg2.exe"; Flags: nowait postinstall skipifsilent; Components: Component2 and not Component1;
这将产生:

  • 如果未选择任何组件,则无复选框
  • 如果选择了两个组件,则有两个未选中的复选框
  • 如果仅选择了一个组件,则选中一个复选框

Err,“如果选择了两个组件,则复选框的默认值为false”为true,但即使仅选择其中一个组件,复选框也将被取消选中。事实上,使用这样的脚本,您总是会得到未选中的复选框。是的,我知道上面脚本的结果会给我未选中的复选框。我想要的是,如果选择了任何一个组件,就会选中一个复选框。是的,我正在寻找这个!!谢谢!:)不客气!我忘了在脚本部分提到,您只能使用多个条目(每个状态一个条目)执行此操作,因为在运行时无法更改标志(您无论如何都不能从条目中删除
未选中的
标志)。好的,再次感谢!我不知道标志只能预先设置。标志必须在编译时知道,因为其中许多标志决定了资源(例如文件)将如何编译为输出二进制文件。但是,可以将这些特殊的
[Run]
条目分离到一个独立的部分,例如
[PostInstallRun]
或类似的内容。顺便说一句,与您的问题类似的是,如何通过传递的命令行参数定义安装后复选框状态(这让我失望,因为它的答案过于复杂,已被接受)。