1. Technology

How to Create a Stub Program to support Self-Extracting Archives


Idea and code by: Peter Carl Barnard.

Recently I decided to create my own compression program, which allows for creation, adding to, extracting from, deleting from, etc. of the “zip” files.

One of the requirements was that this utility must be able to create "self-extractors". Those are zip files with an ".exe" extension that can simply be run, and will extract themselves.


To create a self-extractor, you need a special little .exe called a “stub”. This “stub” gets pulled into the final .exe (self-extracting) file and does the extraction work for you.

While there are many ready-made stub programs available on the Net, the problem is that most of these stubs contained manufacturer’s logo, forms etc. Bad. What’s more I couldn’t find a stub that handled password protected zip files - so eventually, I had to resort to writing my own stub.

Building a Stub...

Take a look at the following schema:


      file1.ext, file2.ext, file3.ext, ...
  1. «MySelfExtract.exe» is the self-extractor that your end-user will be need to execute, it contains both the "MyZipFile.zip" (originally created zip file) and "SelfStub.exe" - the stub file we are going to design.
  2. «MyZipFile.zip» is the originally created zip file and contains those files that were compressed into "MyZipFile.zip".
The idea of the stub is simple, in general. Your user is simply going to run "MySelfExtract" - which will hand the control over to "SelfStub.exe" which will in turn provide the extract of "File1", "File2" and "File3" from Zip file "MyZipFile.zip".

To the Stub code...

Note: you'll need to download a very good set of components called Abbrevia that were originally made available by TurboPower. "TurboPower" has since ceased to operate commercially, fortunately some very dedicated people have kept these very useful components going under the Mozilla Public License at SourceForge.

A Stub program is similar to a Console mode (command line) application, where the console window does not get displayed. That said, a stub has no forms – all the code is contained inside the DPR – project file.

Another important issue with writing a stub, is that a stub uses command line parameters and the ParamStr function to return a specified parameter from the command line.

How does this affect our stub? Well, consider that the stub will be "built in" to the overlying self-executing file and thus inherit it's path and name, so we'll use ParamStr(0) to identify which self-extractor the stub should be operating on.

The last thing to remember, is that although our stub will have an ".exe" extension, it cannot be run in it's own right – it is not a program - but merely a facilitator. If you try to run this executable by itself it will fail - it won't be able to identify itself!

Take a look at the full source code to the STUB program

Final step: the self extracting archive

One of the Abbbrevia components (TabMakeSelfExe) provides the following properties (with example values):

SelExe - "MySelfExtract.exe"
StubExe - "SelfStub.exe"
ZipFile - "MyZipFile.zip"

Once these parameters have been supplied, call the "AbMakeSelfExe.Execute" method – and the «MySelfExtract.exe» gets created. That simple.

An alternative is to do the whole thing manually from the command line:

COPY /B "C:\MyZips\SelfStub.exe" /B + "C:\MyZips\MyZipFile.zip" /B "C:\MyZips\MySelfExtract.exe" 
Related Video
Convert Color Photos to Black and White in Photoshop
  1. About.com
  2. Technology
  3. Delphi
  4. Coding Delphi Applications
  5. How to Create a Stub Program to support Self-Extracting Archives using Delphi

©2014 About.com. All rights reserved.