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.
Stub?
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 manufacturers logo, forms etc. Bad. Whats more I couldnt 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: MySelfExtract.exe SelfStub.exe MyZipFile.ZIP
file1.ext,
file2.ext,
file3.ext, ...
- «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.
- «MyZipFile.zip» is the originally created zip file and contains those files that were compressed into "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"
