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

时间:2014-08-25 06:59:10

标签: inno-setup launching-application

我使用Inno Setup设计了我的安装程序,以显示2个组件供用户选择。根据他/她的选择,最后的Finish页面将显示Launch program复选框。如果已选择两个组件,则复选框的默认值为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

我理解我想要的东西,需要完成一些脚本。我不知道该怎么做。

请指导。

1 个答案:

答案 0 :(得分:3)

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

[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;

这会产生:

  • 如果未选择任何组件,则不显示复选框
  • 如果选中了两个组件,则选中两个未选中的复选框
  • 如果仅选择了其中一个组件,则选中一个复选框