Skip to main content
Self-extracting archives (SFX) are executable files that can extract their contents without requiring 7-Zip or any other archiver to be installed.

What are SFX Archives?

An SFX archive combines:
  • A small executable stub (SFX module)
  • The compressed archive data
  • Optional configuration and GUI
The result is a .exe file (Windows) or executable binary (Linux/macOS) that can extract itself.

Creating SFX Archives

Basic SFX Archive

# Windows
7z a -sfx archive.exe files/

# The result is archive.exe that can be double-clicked to extract

With Custom SFX Module

# Use specific SFX module
7z a -sfx7z.sfx archive.exe files/

SFX Module Types

7-Zip includes three SFX modules:

1. Console SFX (7zCon.sfx)

Location: CPP/7zip/Bundles/SFXCon/
7z a -sfx7zCon.sfx installer.exe files/
Features:
  • Command-line interface
  • No GUI dependencies
  • Small size (~100 KB)
  • Ideal for scripts and automation

2. Windows GUI SFX (7z.sfx)

Location: CPP/7zip/Bundles/SFXWin/
7z a -sfx7z.sfx installer.exe files/
Features:
  • Graphical interface
  • User-friendly extraction dialog
  • Size: ~150 KB
  • Best for end-user distribution

3. Installer SFX (7zS.sfx)

Location: CPP/7zip/Bundles/SFXSetup/
7z a -sfx7zS.sfx installer.exe files/
Features:
  • Installation wizard interface
  • Run commands after extraction
  • Set extraction path
  • Overwrite prompts
  • Best for software installers

SFX Configuration

Create a configuration file to customize SFX behavior:

config.txt

;!@Install@!UTF-8!
Title="My Application Installer"
BeginPrompt="Install My Application?"
Progress="yes"
RunProgram="setup.exe"
Directory="C:\\Program Files\\MyApp"
;!@InstallEnd@!

Create SFX with Config

# Create archive with config
copy /b 7zS.sfx + config.txt + archive.7z installer.exe
Or use 7-Zip:
7z a -sfx7zS.sfx installer.exe files/ -c config.txt

Configuration Options

Title
string
Window title for installer
Title="My Software v1.0"
BeginPrompt
string
Message shown before extraction
BeginPrompt="Do you want to install My Software?"
Progress
string
Show progress dialog (“yes” or “no”)
Progress="yes"
RunProgram
string
Program to run after extraction
RunProgram="setup.exe"
RunProgram="hidcon:setup.exe"
Directory
string
Default extraction directory
Directory="C:\\Program Files\\MyApp"
Directory="%%T\\MyApp"
ExtractDialogText
string
Text in extraction dialog
ExtractDialogText="Please wait while files are extracted..."
OverwriteMode
string
How to handle existing files
  • 0 - Ask user
  • 1 - Overwrite without prompt
  • 2 - Skip existing files
OverwriteMode="0"
InstallPath
string
Installation path with user prompt
InstallPath="C:\\Program Files\\MyApp"

Path Variables

Use special variables in paths:
VariableDescriptionExample
%%SSystem directoryC:\Windows\System32
%%PProgram FilesC:\Program Files
%%TTemp directoryC:\Users\...\AppData\Local\Temp
%%HomeDrive%%Home driveC:
Directory="%%T%%\\MyApp"
RunProgram="%%S%%\\notepad.exe"

Examples

Software Installer

;!@Install@!UTF-8!
Title="MyApp 2.0 Setup"
BeginPrompt="Install MyApp 2.0?"
Progress="yes"
ExtractDialogText="Installing MyApp..."
Directory="C:\\Program Files\\MyApp"
RunProgram="setup.exe"
RunProgram="hidcon:cleanup.bat"
;!@InstallEnd@!
7z a temp.7z files/
copy /b 7zS.sfx + config.txt + temp.7z MyAppSetup.exe

Silent Extraction

;!@Install@!UTF-8!
Progress="no"
Directory="%%T%%\\extract"
RunProgram="hidcon:install.bat"
;!@InstallEnd@!

User-Interactive Installer

;!@Install@!UTF-8!
Title="Photo Gallery v3.5"
BeginPrompt="Do you want to install Photo Gallery?\n\nClick OK to continue."
Progress="yes"
ExtractDialogText="Extracting files..."
InstallPath="C:\\Program Files\\PhotoGallery"
OverwriteMode="0"
RunProgram="%%InstallPath%%\\setup.exe"
;!@InstallEnd@!

Creating Multi-Platform SFX

Linux/macOS SFX

Create self-extracting shell archives:
#!/bin/bash
# Create SFX for Linux
cat sfx_stub.sh archive.7z > installer.sh
chmod +x installer.sh

sfx_stub.sh

#!/bin/bash
ARCHIVE_START=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`
tail -n+$ARCHIVE_START $0 | 7z x -si
exit 0
__ARCHIVE_BELOW__

SFX Compression Options

Use maximum compression for SFX archives:
# Maximum compression SFX
7z a -sfx -mx=9 -md=64m -mfb=273 installer.exe files/

# With encryption
7z a -sfx -p -mhe=on -mx=9 installer.exe files/

SFX Module Source Code

The SFX modules are built from:
  • Console SFX: CPP/7zip/Bundles/SFXCon/
    • Main file: SfxCon.cpp
    • Size: ~100 KB
    • No GUI dependencies
  • GUI SFX: CPP/7zip/Bundles/SFXWin/
    • Main file: SfxWin.cpp
    • Uses Windows Common Controls
    • Size: ~150 KB
  • Setup SFX: CPP/7zip/Bundles/SFXSetup/
    • Main file: ExtractCallback.cpp, ExtractEngine.cpp
    • Full installer functionality
    • Size: ~160 KB

Building Custom SFX Modules

You can build custom SFX modules from source:
# Windows with Visual Studio
cd CPP/7zip/Bundles/SFXWin
nmake

# Result: 7z.sfx

Best Practices

Use SFX archives for:
  • Software distribution
  • Installation packages
  • Sending to users without 7-Zip
  • One-click extraction
Considerations:
  • SFX files are larger (adds ~100-160 KB)
  • Some antivirus software may flag SFX files
  • Test on target systems
  • Sign executables to avoid security warnings

Code Signing

Sign SFX executables to avoid security warnings:
# Windows code signing
signtool sign /f certificate.pfx /p password /t http://timestamp.server installer.exe

Troubleshooting

SFX Won’t Run

  • Check compatibility: Ensure SFX module matches target OS
  • Antivirus: Whitelist or sign the executable
  • Permissions: Run as administrator if needed

Custom Module Not Found

# Specify full path to SFX module
7z a -sfx"C:\\7-Zip\\7zS.sfx" installer.exe files/

See Also

Build docs developers (and LLMs) love