Reputation: 46830
I need to find a way to reference environment variables INSIDE the Inno Setup script file (.iss)...
I've found plenty of references to MODIFYING the environment from an .iss, but none on how to actually use it. Is this possible?
Upvotes: 30
Views: 22938
Reputation: 202682
The syntax is different, if you want to resolve the variable on install-time or on compile-time. That's why there are two existing answers that show completely different solutions that work for some and not others. Because different readers look for different things here.
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');
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')}';
Upvotes: 24
Reputation: 33617
I couldn't figure out how to use the {%name|default}
syntax, so this is how I implemented the same (I needed to specify a default value when the env var is not present):
#if GetEnv('EXTRA_FILE_LOCATION') != ""
#define EXTRA_LOCATION=GetEnv('EXTRA_FILE_LOCATION')
#else
#define EXTRA_LOCATION="."
#endif
Source: {#EXTRA_LOCATION}\ExtraFile.data; DestDir: {app};
Upvotes: 0
Reputation: 145
If the variable TEMP
does not exist then the default value will be used - ..\..\distr\
))))
OutputDir={#StringChange(GetEnv("TEMP")+"\", StringChange(GetMD5OfString(GetEnv("TEMP")), "d41d8cd98f00b204e9800998ecf8427e", "\"), "..\..\distr\")}
Upvotes: 1
Reputation: 73295
According to this page in the Inno Setup documentation, the value of environment variables can be retrieved using the following syntax:
{%name|default}
Upvotes: 18
Reputation: 411
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};
Upvotes: 20