Fix 7-Zip SFX RunProgram Failure: Select Correct Stub for Auto-Execution
Subject: 7-Zip SFX, RunProgram Not Working, Windows Deployment, Silent Install
1. Problem Statement
When creating a self-extracting archive (EXE), the RunProgramdirective in the config file is ignored. The EXE either pops up an "Extract to" dialog or does nothing.
2. Root Cause Analysis
The failure is caused by using the wrong SFX module (Stub). 7-Zip has two incompatible types:
|
Feature |
Standard SFX (Wrong) |
Installer SFX (Correct) |
|---|---|---|
|
Binary |
|
|
|
Size |
~38 KB |
~128 KB |
|
Supports RunProgram |
No |
Yes |
|
Behavior |
Only extracts files |
Executes commands |
Conclusion: 7z.sfxdoes not have the logic to execute programs. It will always ignore RunProgram.
3. Solution: Standard Implementation
Step 1: Prepare the Stub
Obtain 7zSD.sfx from the official LZMA SDK. Do not use any random .exefile.
Step 2: Define Configuration
Create config.txt. Encoding must be UTF-8 without BOM.
;!@Install@!UTF-8!
Title="Deployment Tool"
; Extract to current directory
InstallPath=".\\ "
; Command to run after extraction
RunProgram="scripts\\entry.bat"
;!@InstallEnd@!
Step 3: Build Command (PowerShell)
Concatenate the files in binary mode.
# Create 7z archive
& "7za.exe" a -t7z "archive.7z" "source_folder" -mx=9
# Combine Stub + Config + Archive
$output = [System.IO.File]::ReadAllBytes("7zSD.sfx") +
[System.IO.File]::ReadAllBytes("config.txt") +
[System.IO.File]::ReadAllBytes("archive.7z")
[System.IO.File]::WriteAllBytes("installer.exe", $output)
4. Troubleshooting Checklist
If the issue persists, verify the following:
|
Check Item |
Expected Result |
|---|---|
|
Stub File Size |
~128 KB (Not 38 KB) |
|
Config Encoding |
UTF-8 without BOM |
|
Path Separator |
Double backslashes ( |
|
Archive Type |
7z (Not ZIP) |
5. Verification
Test the stub with a minimal config:
;!@Install@!UTF-8!
RunProgram="cmd.exe"
;!@InstallEnd@!
-
Success: A CMD window opens.
-
Failure: An "Extract to" dialog appears (Stub is wrong).
6. Technical Constraints
-
ZIP Format: Not supported.
7zSD.sfxonly reads 7z format. -
Windows Native: Cannot be extracted by Windows Explorer (requires 7-Zip/WinRAR).
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)