How to Create 7-Zip SFX with Custom Setup Scripts
Yes, 7-Zip can create self-extracting (SFX) archives that automatically execute custom installation setup scripts or commands upon extraction. While the basic 7-Zip GUI only creates simple self-extracting archives, you can combine 7-Zip's command-line tool, an extended SFX module, and a configuration file to build automated, scripted installers.
Required Components
To create an advanced SFX installer, you need three files:
- The SFX Module (
7zS.sfxor7zSD.sfx): Available in the official 7-Zip Extra package, these modules support configuration directives and script execution. - The Configuration Script (
config.txt): A plain text file defining the installer's behavior and the commands to run. - The Payload Archive (
archive.7z): A standard 7z archive containing your program files and any setup script (such as a.bat,.cmd,.ps1, or.exe).
Step 1: Create the Payload Archive
Compress your application files and your custom installation script
into a standard .7z file using 7-Zip:
7z a archive.7z ./source_files/*Step 2: Write the Configuration Script
Create a text file named config.txt encoded in
UTF-8. Use the following structure to define the
execution parameters:
;!@Install@!UTF-8!
Title="Application Setup"
BeginPrompt="Do you want to install this application?"
ExecuteFile="setup.bat"
ExecuteParameters="/silent"
;!@InstallEnd@!
Key Configuration Directives:
Title: The window title displayed during extraction.BeginPrompt: A confirmation message shown before extraction begins.ExecuteFile: The script or binary to launch after files are extracted.ExecuteParameters: Optional command-line flags passed to the executed file.RunProgram: An alternative directive for launching standard Windows commands directly.
Step 3: Combine Files into the Final Executable
Combine the module, configuration script, and payload archive into a single executable using the Windows binary copy command:
copy /b 7zS.sfx + config.txt + archive.7z Installer.exeWhen a user runs Installer.exe, the package extracts the
compressed contents into a temporary directory, automatically runs the
designated setup script with any specified parameters, and cleans up the
temporary files after execution completes.