安装exe时使用INI文件确定目标路径

问题描述

我需要在两个不同的目标文件夹中安装一个安装程序(通过 inno setup 创建)。

我的目标是在安装时使用 ini 文件来确定目标目录。

Setup.ini 文件

[Settings]
#======================================================================
DestDir=C:\\Software\\Path1
#======================================================================

Inno 安装文件

#define DestinationDir ReadIni("Setup.ini","Settings","DestDir","")

[Files]
Source: "D:\Publish\MyService.exe";                 DestDir: "{#DestDir}";    Flags: ignoreversion

[Run]
Filename: "{#DestDir}\MyService.exe";        Parameters: "-i -name MyService-display ""My Service""";       StatusMsg: "Installing my service";

我将安装程序文件 (setup.exe) 与 .ini 文件(设置为 path1)一起复制到服务器并运行安装程序。我希望将 myService.exe 文件复制到 Path1(“C:\Software\Path1”)中。

enter image description here

然后我将 .ini 文件更改为以下并重新运行安装程序。我希望将 myService.exe 文件复制到 Path2(“C:\Software\Path2”)中。

[Settings]
#======================================================================
DestDir=C:\\Software\\Path2
#======================================================================

然而,这根本不起作用。似乎只有在我们通过 inno setup 创建安装程序时才能引用 ini 文件,而不是在执行安装程序时。有什么建议可以实现这一目标吗?

解决方法

您的代码正在使用 preprocessor。预处理器在编译时进行评估。它对运行/安装时没有影响。


Inno Setup 具有用于指定目标路径的内置功能。您可以使用 command-line switch /DIR= 来指定路径:

setup.exe /DIR=C:\Software\Path1

另一种选择是使用 /LOADINF switch 使用特殊的 INI 文件,如下所示:

[Setup]
Dir=C:\Software\Path1

相关问题:Inno Setup Load defaults for custom installation settings from a file (.inf) for silent installation