I’ve used 7-Zip for two years by now. In the beginning I was bit sceptic about it because of the poor-quality icons in their toolbar (they are not very appealing). Now, I cannot live without it. It even have become part of the tool ecosystem I use at work. Currently, I am using it to package an installer. Let’s see how it works and how this could be valuable to you.
In first place, let’s get the concepts before getting our hands dirty. To build our self-extracting installer, we need three elements:
- A SFX header, that is, a piece of binary code which implements the extraction algorithm.
- A special config.txt file.
- An archive with our software!
Download 7z Library (7z-extras) and extract in 7-zip’s folder. This archive contains the SFX for Windows installers.
The SFX header is what contains the binary code needed to build the executable. If you need to change the language, the icon or other “resources”, you might try using Resource Hacker.
The payload for this SFX module is around 150KB. Not bad at all :)
config.txt file you would better use an advanced text editor like Notepad++. Although this is not documented so well, you need to use Unicode encoding and Unix new line separator (
'n', unlike Windows’
According to 7-zip’s help, every key-value pair must follow this format:
Now let’s see an example
Title="Title of the Window"
BeginPrompt="Do you want to install this application?"
- If you want to avoid the
BeginPromptmessage box, just don’t include that line in the result config.txt.
Progressis “yes” or “no”. This shows or hides a progress bar while extracting the file.
ExecuteFileis the name of the installer (tipically setup.exe). If you just want to call an executable file not included in the SFX, use
RunProgram. For instance: “RegSvr32 component.ocx”.
ExecuteParametersis what you expect. Most of the time you won’t need it.
Well, this step is straightforward. Just check 7-zip help if you need something more advanced, but this should be enough:
PathTo:7z.exe -a archive.7z *.exe *.dll *.xml (whatever files you need to include in your release.)
Once we have the SFX header, our config.txt file and our compressed files, we can build our self-extracting archive. In a console, run the following command:
copy /b PathTo:7zS.sfx + config.txt + archive.7z MyProductInstaller.exe
Most IDEs let you run a command if the build have been successful. Just call our build.bat and there you are!