Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

I figured it out after fiddling with it:

:: zip
"C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx dirname
share|improve this answer
If you figured out a solution, please mark this as the accepted answer. – nhinkle Dec 12 '10 at 23:34

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
share|improve this answer

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.

share|improve this answer
didn't work. see question revision. – djangofan Jul 6 '10 at 20:41
looks like you just had to move a few things around. I'm glad it worked out for you. – Daisetsu Jul 6 '10 at 21:47

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

share|improve this answer
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 Jul 6 '10 at 21:25
Then use one of the following environment variables: ProgramFiles= ProgramFiles(x86) – Mark Allen Jul 6 '10 at 21:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.