App-Fu: Commandline 7-zip Sfx

Hidden feature: 7-zip can create commandline self-extracting archives, for use in batch-fu. The GUI simply lacks a checkbox.

A) Here’s the goofy commandline way.
The -t arg is optional, but it’s a reminder that this is, deep-down, the 7z format.

“…\7-Zip\7z.exe” a -t7z somefile.exe somedir\ -sfx

B) Self-extracting archives are literally archives with an executable header tacked on at the beginning.
You can turn an existing 7z archive into an sfx by concatenating.

copy /b “…\7-Zip\7zCon.sfx” + somefile.7z somefile.exe

Or if you’ve got unixutils…

cat “…\7-Zip\7zCon.sfx” somefile.7z > somefile.exe

C) The third way is a cheat.
Replace the graphical header “…\7-zip\7z.sfx” with a copy of 7zCon.sfx. That way the right-click:”Add to Archive…” dialog will make commandline sfx’s all the time instead.

 

Z) Then copy that exe anywhere and the following will extract to an arbitrary location (-o) silently (-y).

somefile.exe x -o”C:\Somewhere\besides\here\” -y

Tags:

Leave a Reply