Inno Setup:运行 外部驱动程序安装程序仅当其组件被选中时

Inno Setup: Run external driver installer only if its component is checked

我想为我的应用程序创建一个用户友好的安装程序。

其实很基础:

[Setup]
AppName=My Application
AppVersion=2.5
DefaultDirName={pf}\MyApplication
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyApp.exe
OutputDir=userdocs:MyApp
SetupIconFile=icon.ico
UninstallIconFile=icon.ico

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "driver"; Description: "Driver files"; Types: full
Name: "driver\USB"; Description: "USB-Driver"; Types: full; Flags: checkablealone
Name: "driver\MISC"; Description: "MISC-Driver"; Types: full ;Flags: checkablealone

[Files]
Source: "*.exe"; DestDir: "{app}"; Components: program
Source: "*.dll"; DestDir: "{app}"; Components: program
Source: "*.bmp"; DestDir: "{app}"; Components: program
Source: "*.ini"; DestDir: "{app}"; Components: program
Source: "USBDriver.exe"; DestDir: "{app}"; Components: driver\usb
Source: "MiscDriver.exe"; DestDir: "{app}"; Components: driver\misc

[Run]
Filename: "{app}\USBDriver.exe"; Description: "Install USB-Driver"; Flags: postinstall skipifdoesntexist
Filename: "{app}\MiscDriver.exe"; Description: "Install Misc-Driver"; Flags: postinstall skipifdoesntexist runascurrentuser


[Icons]
Name: "{commonprograms}\MyApp"; Filename: "{app}\MyApp.exe"
Name: "{commondesktop}\MyApp"; Filename: "{app}\MyApp.exe"

用户应该决定是否要安装这两个驱动程序。 为此,我创建了两个 [Run] 部分条目。

安装完成后,应该开始安装驱动程序。 实际上那里有马车。如果我没有检查驱动程序安装组件,或者只检查其中一个,我就会遇到问题。尽管如此,安装程序仍然运行我在安装后选择的两个安装文件。

如何在用户勾选安装组件后才开始安装驱动?

提前致谢

您必须使用 the Components parameter 过滤 [Run] 部分条目,就像您已经过滤 [Files] 部分中的条目一样:

[Run]
Filename: "{app}\USBDriver.exe"; Description: "Install USB-Driver"; \
    Components: driver\usb; Flags: postinstall
Filename: "{app}\MiscDriver.exe"; Description: "Install Misc-Driver"; \
    Components: driver\misc; Flags: postinstall runascurrentuser

请注意,我已经删除了 skipifdoesntexist 标志,因为我认为这是您解决问题的尝试。通常你不应该使用它,因为它的唯一作用是:

If this flag is specified in the [Run] section, Setup won't display an error message if Filename doesn't exist.


如果您想要 运行 安装程序总是在安装时,只需删除 the postinstall flag 并将 Description 参数替换为 StatusMsg 参数。

您可能根本不想将安装程序复制到 {app}。将它们安装到 {tmp} 并使用 the deleteafterinstall flag 让主安装程序在安装后删除它们。

[Files]
Source: "USBDriver.exe"; DestDir: "{tmp}"; Components: driver\usb; Flags: deleteafterinstall
Source: "MiscDriver.exe"; DestDir: "{tmp}"; Components: driver\misc; Flags: deleteafterinstall

[Run]
Filename: "{tmp}\USBDriver.exe"; StatusMsg: "Installing USB-Driver"; \
    Components: driver\usb; Flags: runasoriginaluser
Filename: "{tmp}\MiscDriver.exe"; StatusMsg: "Installing Misc-Driver"; \
    Components: driver\misc

(没有postinstall标志,默认是runascurrentuser,因此我切换了标志)。