What is 7-Zip’s command-line argument to create a self extracting archive?

8

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.

djangofan

Posted 2010-07-06T20:29:09.727

Reputation: 2 459

Answers

9

I figured it out after fiddling with it:

:: zip
"C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx dirname
pause

djangofan

Posted 2010-07-06T20:29:09.727

Reputation: 2 459

4

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

MrPhilTX

Posted 2010-07-06T20:29:09.727

Reputation: 41

2

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")

Sathyajith Bhat

Posted 2010-07-06T20:29:09.727

Reputation: 58 436

it 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. – djangofan – 2010-07-06T21:25:24.083

Then use one of the following environment variables: ProgramFiles= ProgramFiles(x86) – Mark Allen – 2010-07-06T21:53:33.900

1

Keep it basic. The manual says the default:

  • type is 7z
  • compression method is 5 ( use 0 for copy and 9 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

Todd Partridge

Posted 2010-07-06T20:29:09.727

Reputation: 235

0

With 7-zip there is command line version available called 7z.exe you can download it from 7-zip's website. To create a self extracting installer use the -sfx flag followed by a number for the compression amount.

Daisetsu

Posted 2010-07-06T20:29:09.727

Reputation: 5 195

didn't work. see question revision. – djangofan – 2010-07-06T20:41:44.933

looks like you just had to move a few things around. I'm glad it worked out for you. – Daisetsu – 2010-07-06T21:47:56.720