The newest version of Borland zero-administration database - Borland InterBase 7.5.1 - ships with the new Windows installer that supports silent install. I was suprised how easy it is to create a custom installer application that installs InterBase completely transparently to the end-user.
Interested in writing custom installers in Borland Delphi 2006? The application that I’m going to describe here is a "proof-of-concept" one. Its goal is to illustrate the steps, and it can serve as a good starting point for production quality installer.
I’m assuming that you have Delphi installed. I would recommend using the latest version - Delphi 2006 - which is really rock solid. Older versions would do as well. However InterBase has to be version 7.5.1. If you do not have one, go to Intebase home page and download the free trial. The name of the file is "7.5.Windows.zip" and it’s slightly more than 40 megs. Note that Interbase version that shipped with Delphi 2006 is 7.5, and not 7.5.1, so you probably really need to download it. After a while after downloading you should receive by e-mail a registration file that is needed to activate InterBase. These registration files are typically text files with a name "regxxx.txt", where "xxx" is a number. These two files are all you need to start.
Inside the zip file you’ll find the "Windows_installer.txt" with the detailed information on how to perform the silent install. For your convinience I’ve copied some of the information from this file in here:
"Interbase 7.5.1 has a new Windows only installer to help make embedding InterBase easy. The installer is located at Disk1InstDataWindowsVM of the CDImage and is titled ib75_install.exe. Command line options for ib75_install.exe:
/S silent mode,
/M=filename this settings will contain the settings you want for your installation
Here is an example value file:
MAINDIR=C:\Program FilesBorlandInterBase
TCP_PORT=3050
INSTANCE=gds_db
COMPONENTS=A,C
ACTIVATION_FILE=regxxxx.slip
The variables are defined as
MAINDIR- The Location of the InterBase Root Directory
TCP_PORT- default is 3050
INSTANCE- default is gds_db
COMPONENTS- This is a comma separated list of the Compnents that will be installed
A = Server and Client
B = Client only
C = Documentation
D = Registration (Will not work in silent mode)
ACTIVATION_FILE- The filename of your Interbase activation file. This file should be placed in the same directory as the installer. This file can be a*.slip file or a *.txt file.
example: assume that-
MAINDIR=C:\Program FilesBorlandInterBase
TCP_PORT=3050
INSTANCE=gds_db
COMPONENTS=A,C
ACTIVATION_FILE=regxxxx.slip
are saved in a file named "values.txt". Execute "ib75_install.exe /s /m=values.txt". This will launch a silent install with the settings from the value file. Value files can also be used in Graphical mode by executing ib75_install.exe without the /s flag."
That sounds great. Before attempting to write an installer, I’ve tried to install InterBase on a clean WindowsXP installation in the VMWare image. First all neccessary files have to be copied in an arbitrary location on the target machine; say C:\temp folder. To make my life easier I’ve created a little batch file "ib751silent.bat" with the above command to execute the installer.
So at this point in my temporary folder on a target machine I’m having the following files:
-> ib75_install.exe (the actual Interbase 7.5.1 installer)
-> reg626.txt (registration file received from Borland)
-> values.txt (installation value file)
-> ib751silent.bat (batch file for running install)
Now it is the time to test installation. Just execute "ib751silent.bat" from command-line or from Windows Explorer, and moment later - few seconds in case of my laptop - Interbase is installed.
That’s great! If the process is so simple, why not to make it even simpler by creating a custom Delphi application that would do all these steps for us?
The first question is how we could embed arbitrary files in a Delphi Win32 executable? Let’s google it out. Few seconds later I’ve found "Delphi Programming: Inside the EXE" article by Zarko Gajic, that details all the steps how one can put arbitrary binary content inside Delphi executable. (BTW Zarko is a great author and Delphi expert. Respect.)
Consequently to embed my four files in the executable, I had to first create a *.rc (resource script) file, with names, types, and locations of resources to be linked into executable, then run this file with resource compiler that ships with Delphi (BRCC32) to generate *.res file. The last step is to add inside my Delphi code a statement that instructs the compiler to link in a custom resource file.
Here are the steps:
1) Create a brand new Delphi Win32 VCL Forms application and save it (for example as "MySetup").
2) Create a new text file, ane rename it to for example "IB.rc". Inside this file put the following lines:
ib_install RCDATA ib75_install.exe
regfile RCDATA reg626.txt
values RCDATA values.txt
batch RCDATA ib751silent.bat
3) Generate IB.RES file executing the following command: "brcc32 ib.rc".
4) Inside the Delphi application main form source file locate existing compiler directive "{$R *.dfm}" and add another one:
{$R IB.RES}
5) Recompile the application. You should now notice that the size of your executable has increased from around 300K to almost 20M, which is understandable, because it now contains our resource file.
6) We are now having four different resources that we want to extract from the executable and save on a destination machine. For this purpose let’s add to the main form class the following method that will extract a resource identified by name and save it under a specified name. Add the following procedure to the form class:
procedure TFormMain.ExtractRes(aResName, aTargetFileName: string);
var rStream: TResourceStream; fStream: TFileStream;
begin
rStream := TResourceStream.Create(hInstance, aResName, RT_RCDATA);
try
fStream := TFileStream.Create(aTargetFileName, fmCreate);
try
fStream.CopyFrom(rStream, 0);
finally
fStream.Free;
end;
finally
rStream.Free;
end;
end;
7) Add a button to the form, double-click it, and in the resulting event handler add the following code that will do the whole installation:
uses
ShellAPI;
procedure TFormMain.btbtnInstallClick(Sender: TObject);
var
aOldCursor: TCursor;
begin
aOldCursor := Screen.Cursor;
Screen.Cursor := crHourglass;
try
ExtractRes(’ib_install’, ‘ib75_install.exe’);
ExtractRes(’regfile’, ‘reg626.txt’);
ExtractRes(’values’, ‘values.txt’);
ExtractRes(’batch’, ‘ib751silent.bat’);
if ShellExecute(self.Handle, nil, ‘ib751silent.bat’, nil, nil, SW_HIDE) <= 32 then
ShowMessage(’Failed to execute Interbase installer.’);
finally
Screen.Cursor := aOldCursor;
end;
ShowMessage(’Done.’);
end;
Compile the application. Copy the resulting executable (in my case "MySetup.exe") to a Windows machine without Interbase installed, run it, and just press the button. If everything worked well you should see "Done." message. Go to Windows "Start" menu, and you should find a new program installed - Borland InterBase 7.5.1 Trial.
Summary
First of all, if you want to write a real-life installer based on this example, make sure you contact your local Borland representative regarding Borland InterBase licensining. This example installs only an InterBase free trial.
The source code presented in here is very simple, and it is not enough for production quality setup. It just installs InterBase, and does not care about checking, whether InterBase is not already installed, and it does not delete files it creates. Another potential change to be made is executing the batch file with "ShellExecute". The problem here is that "ShellExecute" does not wait until InterBase is actually installed. It returns immediately. More appriopriate would be to use "CreateProcess" and "WaitForSingleObject" Windows API calls.
{ 9 } Comments
Hey!
(advertise mode on)
If you want to embed custom resources in a Delphi application, you can do so using this:
http://cc.borland.com/Item.aspx?id=21990
It’s my Custom Resource Generator, works up til Delphi 6 for sure(not sure about 2005/6, however I want to redo it :D).
(advertise mode off)
Andrew
Cool, Pawel!
Why would I want to compile my own setup executable in Delphi at all? Don’t get me wrong, your article is an excellent example of how to embed resources of any kind into a Delphi application. And of course I appreciate showing how to use IB 7.5.1 new silent mode.
I’ll certainly use that information to create an InnoSetup installation for my application that integrates an IB install …
very cool ! thanks very much !
Gute Arbeit hier! Gute Inhalte.
Sehr wertvolle Informationen! Empfehlen!
Thanks, the installation worked ok. And to start the service of Interbase in the instance GDS_DB07 through prompt?
Thanks, the installation worked ok. And to start the service of Interbase in the instance GDS_DB07 through command prompt?
Already discovered how it works. Bill Todd and Craig Stuntz helped me. Still, thank you.
Net Start "Instance Name"
Sample: If instance name = GDS_DB07
Net Start IBG_GDS_DB07
Post a Comment