Global and local variables
CreateInstall allows you to define and use two types of variables - global and local variables. The main difference between global and local variables is that the values of global variables are defined and substituted prior to the creation of an installation, while the values of local variables are defined and substituted during the installation process. Lower, we will look at both types of variables in more detail.
As was said above, global variables are replaced by their values prior to the creation of an installation. This replacement occurs at the level of the entire project – that is, you can use global variables in any place in the settings of your project. For example, you can specify global variables in your installation script's command fields or on the pages in the Project tab. Variables in the project are defined in the following way $varname$, where varname is the direct name of the variable. For example, you can specify
Output Folder: $myoutput$\setups Company Name: $MYCOMPANY$
where myoutput contains the path to the folder, and MYCOMPANY is the name of your company.
You can define global variables in three ways.
- Through a menu item: Tools – Global variables. In this case, the defined variables in the list will be general for all of your projects. For example, this could be the name of your company, your website's address, copyright information, etc. When you change one of these general values, it is enough to change it in only one place and then re-build your installations without changing your projects.
- Any project can be used to create installations for various programs, defining global variables for each installation. They are defined in the section Project – Setup – Mulit Build. For example, say your installations are only different in their names and some source files. In this case, you can define the necessary values for each installation in the Multi Build section, and specify the variables themselves in the corresponding settings.
You can also define global variables during the creation of an installation in a command line. For example:
cicmd.exe -v "version=Free;date=07/07/09" c:\Projects\mysetup.ciIn this case, the variables $version$ and $date$ will be replaced in the project by the specified values.
It should be noted that there are predefined global variables, such as path, current date and time, main folders on your computer etc.
From what has been said above, let's draw some conclusions. Global variables, as a rule, are used for some string or numeric values, which can be used in many projects or in the creation of various installations from one project. Do not use predefined global variables, for example $progfiles$ and $appdata$ as installation paths of files in your script. If you do so, they will be replaced by the current values and will be identical for all users, irregardless of their settings and the actual paths to the given folders.
Local variables are created and used in the installation process of your program on the user's computer. As a rule, for the substitution of variable values, its name must be contained between two '#' symbols.
#setuppath#\my folder #varname# Your name: #username#
If any parameter in commands is called Variable Name, then specify only the variable name, without '#' symbols. There are predefined variables, which are calculated from the moment the installation launches. For example, never specify C:\Program Files or C:\Program Files (x86) as the installation path – the user could have the spanish version of Windows or the Program Files folder could be located on the D: disk. It is necessary in all such cases to use variables, which indicate the standard paths on the user's computer. In this case, you need to use the variable #progfiles# to get the folder with installed programs. There is also, for example, a variable #setuppath#, which is the same as #progiles#\#progname#, where #progname# is the name of the program which you specified in your project. By the way, #setuppath# is defined as INSTALL PATH in drop-down lists. So, you can specify one path in two ways:
Path: INSTALL PATH Custom Path: or Path: CUSTOM PATH Custom Path: #setuppath#
It should be noted that you can independently change the value of variables and create new ones with the commands Set Variables, Modify Variable etc. Besides this, there is a selection of functions for work with variables in the Gentee programming language inside the Source Code command.