Sei sulla pagina 1di 6

Creating professional installations using Inno Setup

Product review by Craig Murphy


Theres no doubt about it distributing your most recent and highly prized application as a single setup.exe creates an air of confidence and provides the end user with their first impression of your application. Whats more, if you incorporate the application configuration and database settings, etc. into this magical setup.exe, then you may save yourself many hours of frustration, often spent on telephone to clients running early version of Windows 98 without the Microsoft Data Access Components (MDAC), for example. I choose to abandon the major player in favour of a freeware equivalent? Well it certainly wasnt because InstallShield lacked the features that my install required, far from it. In November 1999, I chose Inno Setup because it allowed me to build a setup.exe that fitted onto a floppy disc something that I struggled to achieve with the version of InstallShield at the time. Over the remainder of this article I will be describing how I use Inno Setup to build setup.exe files that are very lightweight, i.e. they dont carry much baggage with them. To contrast the lightweight install, I will also describe how Inno Setup can be used to distribute such items as SQL Links. SQL Links should be deprecated by time you read this, however, in the short-term I believe that we will still need to include it in our installs. Given the profusion of freeware applications that are available, its often worth sharing our success stories amongst ourselves it wouldnt be the first time Ive just mentioned something in passing (usually at a BUG meeting) only to have another member jump down my throat for not telling him/her sooner! And it works both ways; Ive been at meetings where another member casually mentions something that has been niggling me for a while and theyve been sitting on the solution, unbeknownst that its a useful snippet.

Introduction
There are many excellent commercial installers available, however sometimes their price tag, whilst well worth the investment, can be too much for the lone developer or the small software house. If you cannot afford the commercial offerings, you have three options. Firstly, you could develop your own this adds a one-off time/cost to your project and may require project-byproject customisations. You would have to design, develop, test, debug, re-test, etc. Suddenly, what started out as small project, becomes a complete project in its own right. This is probably not the most viable option. Secondly, you could just bundle all the files that your applications requires on to a CD and then prepare a complicated crib sheet that contains the instructions required to perform an installation. This is potentially fraught with danger for example, what if the machine that you are installing your application onto already has a newer version of a particular DLL? Do you overwrite it? Do you ask the user? Do you simply ignore it? These scenarios have to be catered for and catering for them on an application-by-application basis will prove to be a timeconsuming process. Thirdly, you could opt to use a free/shareware installer. There are many of these available from the various freeware/ shareware Internet sites. However, personally speaking, I find that freeware/shareware written using our tools (Delphi, CBuilder, etc.) to be of better quality and usefulness, than the freeware/shareware that has been written use other major development environments they always seem to lack something. To that end, I use a freeware product called Inno Setup.

First Impressions

Figure 1 Inno Setup Welcome dialog

Inno Setup
Inno Setup is a freeware product that is free for personal and commercial use its even supplied with full source code. Jordan Russell developed the tool itself, with assistance from Martijn Laan. It has been in existence since 1997 and as such enjoys the benefits of being tried and tested. As an individual I have been using Inno Setup since 1999 and have found it to be particularly fit for purpose, Inno Setup does what it says on the tin. However, as a company our tool of choice was InstallShield. So why did

Inno Setup has a professional finish something that figure 1 demonstrates. Inno Setup essentially borrows the Microsoft PowerPoint Welcome dialog (a design pattern for common user interface components?) by offering a variety of options. Naturally its possible to create a blank installation script using the Create a new empty script file option, however a more useful approach is the Create a new script file using the Script Wizard. The wizard itself is powerful enough to create installations that are non-trivial, i.e. they contain your application, files that accompany your application, directories that your

application requires, a license file (RTF), a before and after file (both RTF) and the usual application name and version information etc. The before file is a useful RTF file that is displayed before the install application actually begins to cause any damage very useful for displaying are you really sure that you want to continue-style information. In some cases, I have used the before file to warn the user that the application they are about to install requires a minimum screen resolution although it hasnt stopped some users from continuing with the install, only to find that they can only see three-quarters (if theyre lucky) of the application! The after file works in the same way as the before file its an RTF file that is displayed after the installation application has completed the installation of your application, written to the Registry (if required) and generally left a footprint on the users machine. I tend to use the after file to convey first-line support information, i.e. provide the user with the telephone number they should call in the [unlikely] event of an application error (I try not to make it my own number!)
Figure 4

demonstrates that we can configure precisely where our application is installed. By default, the local Program Files directory is assumed, although this can easily be changed. At this stage its also possible to enable or disable the users ability to change the destination directory. Whilst this may be useful in some scenarios, perhaps where a standard desktop an common directory structure exists, its unlikely that you would force your application into a particular directory on a frequent basis.

Figure 2

presents the first step of the Script Wizard. Even here it is possible to create an empty script file that requires us to populate it manually. With a little bit of practice, populating the script file manually isnt such a daunting task, far from it.

Figure 5

allows us to specify the application .exe. It also allows us to specify other files and directories that our application requires. By default however, Inno Setup assumes that any files that are included as part of the installation will be copied into the application installation directory. It is not until the file is selected and the Edit button is pressed before we are able to specify a destination subdirectory which is highlighted by

Figure 3

is a little meatier its asking for information about the application that its creating an install script for. The items in bold are required items that must be provided. Its always useful to include the application version number, as the installation application will use this as the first user prompt before it installs any files on the users machine.

Figure 6

Assuming that weve just gone through the Script Wizard accepting the defaults, Listing 1 presents the INI file that the Script Wizard creates. As can be seen, Inno Setup uses an INI file format to record the information about your application installation. Thus we have the ability to create a shell installation using the Script Wizard, then use Inno Setups internal colour-coding editor to augment the INI file. It is a real INI file; we can add comments as required and can comment lines out.

Looks good
Figure 7

demonstrates that we have precise control over the icons that are created. At this point we are able to control whether an uninstall option is available to the user even if we choose not to offer this option, the ability to uninstall your application is still available via the Control Panel, Add Remove Programs option.

Figures 10 through to 15 present the installation application that Listing 1 creates. As can be seen, Inno Setup creates a very polished and professional finish to the final installation application. Its consistent too if you use Inno Setup for a number of your applications, the look and feel is so similar to that of the commercial installation creation applications that most users cant tell the difference thats how easy the wizard approach to installations should be.

Figure 10

Figure 8

allows us to specify the RTF files that make up the licence file and the before and after files (mentioned earlier in this article). These files are optional in their own right, and if they arent specified the installation application simply will not display those particular stages of the installation wizard.
Figure 11

Figure 9

finally wraps everything up and advises the user that the application has been successfully installed. Obviously this doesnt mean that the application will work thats up to you and me to test and test again, however we have created a visually pleasing installation application that the majority of end users will like.

Figure 12

and many other tricks. Installing the BDE for example, is the simple matter of including BDEINST.DLL you can find this file inside BDEINST.CAB, which is in your \Program Files\Common Files\Borland Shared\BDE directory, along with BDEINST.TXT. In addition, youll need MiniReg.exe which is available via the third party section of the Inno Setup web site. MiniReg.exe allows the installation application to invoke the BDE installation. Thus we need to add MiniReg.exe to the [RUN] section of the installation script:
[Run] Filename: {tmp}\MiniReg.exe; Parameters: {tmp}\BdeInst.dll

Figure 13

We also have to specify that MiniReg.exe and BDEINST.DLL are part of the installation in this instance we copy the files into a local temporary directory, indicated by the Inno Setup constant {tmp}. This is also the place to specify any SQL Links drivers that your application requires in this instance I have chosen to include the InterBase drivers:
[Files] Source: MiniReg.exe; DestDir:{tmp} Source: BDEINST.DLL; DestDir:{tmp} Source: SQLINT32.DLL; DestDir: {pf}\Common Files\Borland Shared\BDE; CopyMode:alwaysoverwrite; Source: SQL_INT.CNF; DestDir: {pf}\Common Files\Borland Shared\BDE; CopyMode:alwaysoverwrite;

Figure 14

The final change that is required to deliver a BDE/SQL Links install is a change to the registry. Inno Setup allows full access to the registry, limited only by the permissions of the current user. Heres a snippet of the [REGISTRY] section the full section contents can be found in Listing 2:
[Registry] Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\

So it seems that Inno Setup thinks of everything its possible to have simple installations and also the more complicated installations that involve such additions as the BDE and SQL Links. Listing 2 presents a working installation script for a reasonably large application that was developed for an oil company. As can be seen it uses SQL Links and also as a number of image files included too they are copied to the application installation directory, inside an images directory. Similarly, the file config.xml is copied into the config directory.

Figure 15

By default, Inno Setup creates an installation application that mimics the Windows 2000/XP installation wizards. It is possible, however, to force Inno Setup to create a traditional installation application (the one with the gradient fill in the background). However, this option is not available via the Script Wizard, but is available after the Script Wizard has created the INI file that make up your applications install script. Inside the [SETUP] section we can add the following value/pair:
WizardStyle=classic.

Summary
Over the course of this article I have describe the Inno Setup tool that can build a installation application (e.g. setup.exe) for your applications. Inno Setup is ideal for creating installation applications very quickly, so much so, I even create installation applications for early prototypes this actually saves a little time downstream as the installation script builds up iteratively over the course of the master applications development. Gone are the days of dread when an application is finally ready to ship and somebody asks you to create a professional installation (unless of course, youre lucky enough to be in an environment with support personnel who are paid and able to perform this sort of task!)

Ah, but what about the BDE?


If Inno Setup is so good, why not use it to install such things as the BDE or SQL Links? Well, it is possible, and the Inno Setup web site provides details of how do achieve this

So, if you thought that professional installation applications were only for the rich and corporate developers, think again Inno Setup brings flexible and powerful installation applications for free. Finally, whilst Inno Setup uses INI files to store and manage the components that make up your application, it is possible to use a graphical front-end too there is a link to this tool from the Inno Setup website.

Listing 2 A more complicated setup script


; AUTOEST 3 SETUP.EXE SCRIPT ; 16/01/2002 CAM images directory added ; 30/01/2002 CAM blank.xls became a template, blank.xlt [Setup] AppName=AutoEst 2002 AppVerName=AutoEst 2002 - Estimating System AppCopyright=Copyright 1999-2002 Currie & Brown DefaultDirName={pf}\AutoEst2002 DefaultGroupName=AutoEst 2002 Uninstallable=1 UninstallIconName=Uninstall AutoEst 2002 WizardStyle=modern InfoBeforeFile=Before.rtf AlwaysCreateUninstallIcon=true [Run] Filename: {tmp}\MiniReg.exe; Parameters: {tmp}\BdeInst.dll [Dirs] Name: {app}\XLS Name: {app}\config Name: {app}\images Name: {pf}\Common Files\Borland Shared\BDE

Resources
The latest version of Inno Setup: http://www.jrsoftware.org/ or http://www.jordanr.cjb.net/ Craig is an author, developer, speaker and Dilbert Evangelist he specialises in all things XML, particularly SOAP and XSLT. He can be reached via e-mail at: Craig@isleofjura.demon.co.uk, or via his web site: www.craigmurphy.com (where you can also find the source code and PowerPoint files for all of Craigs UK-BUG articles and presentations).

Listing 1 Creating a setup script using the wizard


; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! [Setup] AppName=My Program AppVerName=My Program 1.5 AppPublisher=My Company, Inc. AppPublisherURL=http://www.mycompany.com AppSupportURL=http://www.mycompany.com AppUpdatesURL=http://www.mycompany.com DefaultDirName={pf}\My Program DefaultGroupName=My Program ; uncomment the following line if you want your installation to run on NT 3.51 too. ; MinVersion=4,3.51 [Tasks] Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:; MinVersion: 4,4 [Files] Source: D:\Program Files\Inno Setup 2\Samples\MyProg.exe; DestDir: {app}; CopyMode: alwaysoverwrite [Icons] Name: {group}\My Program; Filename: {app}\MyProg.exe Name: {userdesktop}\My Program; Filename: {app}\MyProg.exe; MinVersion: 4,4; Tasks: desktopicon [Run] Filename: {app}\MyProg.exe; Description: Launch My Program; Flags: nowait postinstall skipifsilent

[Files] Source: AUTOEST3.EXE; DestDir: {app} Source: BLANK\ESTIMATE3.GDB; DestDir: {app} Source: BLANK\LOOKUP3.GDB; DestDir: {app} Source: BLANK\BLANK.XLT; DestDir: {app}\XLS Source: INTRBASE.REG; DestDir: {app} Source: images\Scene1.bmp; DestDir: {app}\images Source: images\Scene2.bmp; DestDir: {app}\images Source: images\Scene3.bmp; DestDir: {app}\images Source: images\Scene4.bmp; DestDir: {app}\images Source: images\Scene1_256.bmp; DestDir: {app}\images Source: images\Scene2_256.bmp; DestDir: {app}\images Source: images\Scene3_256.bmp; DestDir: {app}\images Source: images\Scene4_256.bmp; DestDir: {app}\images Source: MiniReg.exe; DestDir:{tmp} Source: BDEINST.DLL; DestDir:{tmp} Source: SQLINT32.DLL; DestDir: {pf}\Common Files\Borland Shared\BDE; CopyMode:alwaysoverwrite; Source: SQL_INT.CNF; DestDir: {pf}\Common Files\Borland Shared\BDE; CopyMode:alwaysoverwrite; Source: config\config.xml; DestDir: {app}\config [UninstallDelete] Type: filesandordirs; Name: {app}\XLS Type: filesandordirs; Name: {app}\config Type: filesandordirs; Name: {app}\images

[Icons] Name: {group}\AutoEst 3; Filename: {app}\AutoEst3.EXE Name: {userdesktop}\AutoEst 3; Filename: {app}\AutoEst3.EXE [Registry] Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\ Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SERVER NAME; ValueData: IB_SERVER:/PATH/DATABASE.GDB Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: USER NAME; ValueData: MYNAME Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: OPEN MODE; ValueData: READ/WRITE Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SCHEMA CACHE SIZE; ValueData: 8 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: LANGDRIVER; ValueData: Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SQLQRYMODE; ValueData: Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SQLPASSTHRU MODE; ValueData: SHARED AUTOCOMMIT Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SCHEMA CACHE TIME; ValueData: -1 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: MAX ROWS; ValueData: -1 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: BATCH COUNT; ValueData: 200 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: ENABLE SCHEMA CACHE; ValueData: FALSE Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: SCHEMA CACHE DIR; ValueData: Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: ENABLE BCD; ValueData: FALSE Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: BLOBS TO CACHE; ValueData: 64 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\; ValueType: string; ValueName: BLOB SIZE; ValueData: 32

Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\ Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\; ValueType: string; ValueName: VERSION; ValueData: 4.0 Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\; ValueType: string; ValueName: TYPE; ValueData: SERVER Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\; ValueType: string; ValueName: DLL32; ValueData: SQLINT32.DLL Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\; ValueType: string; ValueName: DRIVER FLAGS; ValueData: Root: HKLM; Subkey: SOFTWARE\Borland\Database Engine\Settings\DRIVERS\INTRBASE\INIT\; ValueType: string; ValueName: TRACE MODE; ValueData: 0

Potrebbero piacerti anche