10

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.

5 Answers 5

12

I figured it out after fiddling with it:

:: zip
"C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx dirname
pause
0
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
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")

2
  • 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, 2010 at 21:25
  • Then use one of the following environment variables: ProgramFiles= ProgramFiles(x86)
    – Mark Allen
    Jul 6, 2010 at 21:53
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
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.

2
  • didn't work. see question revision.
    – djangofan
    Jul 6, 2010 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, 2010 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .