~2011

7zip self extracting autostart exe

In my searches for an easy way to create a self extracting zip file which would automatically start a command after extract I came across some extra 7zip magic. The following intsructions enables exactly this.

Ingredients

[^1]: The latest version for your architecture * 7z*_extra.7z : http://sourceforge.net/projects/sevenzip/files/7-Zip/ [^1]

[^1]: It's in the same directory * some .exe you want to start. In my test 'notepad.exe'

Steps

  1. Install 7zip!
  2. Make a directory somewhere convenient
  3. Extract the 7zS.sfx from the 7z*_extra.7z into the convenient directory
  4. Create a 7zip file from the notepad.exe file. If you installed 7zip correctly you can right-click 'notepad.exe' and select '7zip - add to archive'.
  5. Put the created 7zip file into the convenient directory
  6. Now create a UTF8 encoded text file called "config.txt" containing the following:
;!@Install@!UTF-8!
RunProgram="notepad\notepad.exe"
;!@InstallEnd@!
  1. Your convenient dir should look as follows:
convenientdir\7zS.sfx
convenientdir\notepad.7z
convenientdir\config.txt

And now the magic. We will concatenate the three files so we will end up with one file. Just open a command prompt and change to the convenient dir. Then issue the following command:

copy /b 7zs.sfx + config.txt + notepad.7z notepad.exe

Test your notepad.exe file by double clicking it :)

If you are using '*nix' to get your Windows work done you van also create the .exe in with a simple shell script:

#!/bin/bash
set -e

7zr a bin.7z notepad.exe
cat 7zS.sfx config.txt notepad.7z > notepad.exe