Can One Use Environment Variables In Inno Setup Scripts?
Answer :
I ran into the same problem when trying to specify the source location of files in the [Files] section. I used the GetEnv function to define a new constant.
#define Qt5 GetEnv('QT5') [Files] Source: {#Qt5}\bin\Qt5Concurrent.dll; DestDir: {app};
According to this page in the Inno Setup documentation, the value of environment variables can be retrieved using the following syntax:
{%name|default}
On install-time
If you need to resolve the variable on the target machine, while installing, you can use the {%NAME|DefaultValue}
"constant".
[Files] Source: "MyApp.dat"; Dest: "{%MYAPP_DATA_PATH|{app}}"
If you need to resolve the variable on the target machine in Pascal Script code, you can use GetEnv
support function.
Path := GetEnv('MYAPP_DATA_PATH');
On compile-time
If you need to resolve the variable on the source machine, while compiling the installer, you can use GetEnv
preprocessor function:
[Files] Source: "MyApp.dat"; Dest: "{#GetEnv('MYAPP_DATA_PATH')}"
You can use the same syntax even in Pascal Script, though it would make sense only in very special circumstances.
Path := '{#GetEnv('MYAPP_DATA_PATH')}';
Comments
Post a Comment