Visual Installer's Scripting
you can create quite complex installations without programming,
but there may be occasions when a scripting language and script
commands can help solve a situation. In the Professional version
of Visual Installer there is a flexible scripting language
available, and in this tip we will show how to use a few
commands in the scripting language. We will show how to copy a
file, rename a file and how to use conditional executions of
lines with code.
Where do I enter script commands?
There is a
script editor available in Visual Installer / Professional. You
can open the script editor by choosing the Execute script
commands menu item in the Special menu:
The script editor look like this:
installation' and 'After installation'
two tabs in the script editor: Before installation
and After installation. You can enter script lines in
both tabs. The difference between them is that the script lines
that are entered in the Before installation tab are
executed before the actual installation process (before file copying
etc.) starts, and the script lines that are entered in the
After installation tab are executed after that the actual
installation process has finished (all files have been copied
etc.). The infograph below shows the process:
commands in Visual Installer can be used in the both tabs,
however, same logic may not always work in both tabs. For
example; if you want to copy a file that is included in the
setup package you must execute the script in the After
installation tab, otherwise there may be no file to copy.
Another example; if you want to backup a file before it is
overwritten by the installer you should execute your backup
script lines in the Before installation tab.
Script code example - How to copy a file
We will start
with something very basic and common: the
command is used to copy a file and this command takes two
parameters: a source file path and a destination file path.
Below we show how this command can be used to copy a file from
C:\folder1 to C:\folder2:
In the example above the info.txt file is copied from
C:\folder1 to C:\folder2. However, hardcoding folders
in this way is normally not so useful. Instead we can use
variables for the folder paths. In the next example we will use
variable contains the path to the installation's main
destination folder. We change the example to this:
In this example the info.txt file is copied from the main
destination folder (%DESTDIR) to a sub folder
beneath the main destination folder with the name backup
(%DESTDIR\backup). This is an easy way to
make a backup of a file.
example - How
to rename a file
In the next
example we will show how to rename a file by using the
command. This command takes also two parameters: the old
filename and the new filename. The filenames must contain a full
file path. The example below shows how to rename a file from
newinfo.txt to oldinfo.txt:
The file that will be renamed (in our example) must be located
in the main destination folder, specified by the
execution of script lines
specific line or lines with script code should only be executed
if a specific condition is met, for example if the setup program
is run in a specific version of Windows. In Visual Installer's scripting language you can use conditional
execution of script lines to achieve this. For example, if a
program only can be run in Windows 7 you can enter a condition
In the example above the MyWin7App.exe application will
only be run in Windows 7. If the operating system, where the
installation program currently is running, is something else,
for example Windows XP, the MyWin7App.exe application
will not be launched. All lines between
will be ignored if the operating system is not Windows 7.
command (in the example above) is used to launch a program.
picture below you can see the script editor with some more
The following commands are used in the script example above:
a file, also if it is write-protected.
file for deletion at uninstallation.
More detailed information about the
scripting language in Visual Installer, and a full reference with all
commands, is available in Visual
See the Script commands - Overview section in
< Tips Index Page