What is 7-Zip’s command-line argument to create a self extracting archive?
Solution 1
I figured it out after fiddling with it:
:: zip
"C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx dirname
pause
Solution 2
The issue you were having is that 7-zip doesn't like spaces in the arguments. So what you wanted was something more like:
"C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx7z.sfx dirname
Solution 3
This should work:
"C:\Program Files\7-Zip\7z.exe" a -t7z -mx5 -sfx archive.exe directoryname -mmt
(PS: Add Program Files\7-zip
to your PATH
environment variable, there by you can access the file directly as 7z.exe
rather than "C:\Program Files\7-Zip\7z.exe"
)
Solution 4
Keep it basic. The manual says the default:
- type is
7z
- compression method is
5
( use0
for copy and9
for ultra) - (
-mmt
is for multi-threading and might be antiquated as the manual lacks its definition.)
So this give the basic answer as:
7z a -sfx archive.exe dir
Related videos on Youtube
Olivier.Roger
I always pay it forward. I ask questions so I can learn and I try to help others.
Updated on September 17, 2022Comments
-
Olivier.Roger over 1 year
I looked everywhere and couldn't find a straight answer from anyone.
If I want to package the contents of C:\Temp into a file called Temp.exe (in 7z format) that is self-extracting, how do I do it in a batch file?
This doesn't work:
"C:\Program Files\7-Zip\7z.exe" a -t7z -mx5 -sfx 7z.sfx directoryname archive.exe -mmt
What I get from that is a self extracting archive called 7z.sfx . Can't figure this out.
-
Olivier.Roger almost 14 yearsdidn't work. see question revision.
-
Olivier.Roger almost 14 yearsit needs to work on anyones system. since 7-zip installs to that directory by default on all windows systems, this makes the script much more likely to run on someone elses system.
-
Daisetsu almost 14 yearslooks like you just had to move a few things around. I'm glad it worked out for you.