How to Create 7-Zip SFX Archive Command Line

Creating a self-extracting archive (SFX) allows recipients to unpack compressed files on Windows systems without needing third-party extraction software installed. This guide explains how to build standard and customized .exe self-extracting archives directly through the 7-Zip command-line interface (7z.exe) using simple switches and module configurations.

Basic SFX Archive Command

To create a basic self-extracting archive, open Command Prompt or PowerShell, navigate to the folder containing your files, and execute the following command:

7z a -sfx archive.exe "C:\Path\To\Files\*"
  • a: Tells 7-Zip to add files to an archive.
  • -sfx: Instructs 7-Zip to use the default self-extracting module (7z.sfx).
  • archive.exe: The name of the resulting executable file.
  • "C:\Path\To\Files\*": The path to the files or directory you want to compress.

Choosing an SFX Module

7-Zip includes multiple pre-compiled SFX modules located in its installation directory (typically C:\Program Files\7-Zip):

  • 7z.sfx: The standard Windows GUI module (extracts via a visual dialog prompt).
  • 7zCon.sfx: The console module (extracts entirely within the command prompt).

To specify a non-default module, append the module name directly to the -sfx switch without spaces:

7z a -sfx7zCon.sfx output.exe input_folder

If the SFX modules are not in the current directory or the system PATH, supply the full path to the module:

7z a -sfx"C:\Program Files\7-Zip\7zCon.sfx" output.exe input_folder

Advanced: Creating a Custom Installer SFX

If you need the SFX to extract silently or automatically launch an executable after extraction, build a standard .7z file first and concatenate it with a configuration file and the SFX module.

  1. Create the initial 7-Zip archive:

    7z a files.7z "C:\Path\To\Files\*"
  2. Create a configuration file named config.txt:

    Save a UTF-8 text file containing the extraction parameters:

    ;!@Install@!UTF-8!
    Title="Application Installer"
    BeginPrompt="Do you want to extract and run the application?"
    RunProgram="setup.exe"
    ;!@InstallEnd@!
  3. Combine the files into a single executable:

    Use the Windows binary copy command (copy /b) to merge the module, the configuration, and the archive into the final executable:

    copy /b "C:\Program Files\7-Zip\7z.sfx" + config.txt + files.7z Setup.exe

The resulting Setup.exe will launch the prompt defined in your configuration and extract the files directly to the destination folder before executing the specified program.