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.

link|improve this question

77% accept rate
feedback

4 Answers

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.

link|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
feedback
up vote 0 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
pause
link|improve this answer
1  
If you figured out a solution, please mark this as the accepted answer. – nhinkle Dec 12 '10 at 23:34
feedback

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

link|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
feedback

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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