How do I make a self extract and running installer
Asked Answered
G

3

64

So currently my users download a zipfile, unzip it and then run setup.exe - I would like them to do this with one click. Using http://www.wikihow.com/Use-7Zip-to-Create-Self-Extracting-excutables i can make a self-extracting exe, but it doesn't actually run the installer.

From this question

Why does 7zip Ignore my InstallPath when making a SFX installer?

it seems I also need an .sfx file so I copied from the other question and created one with the following contents

;!@Install@!UTF-8!
InstallPath="C:\\test"
GUIMode="2"
RunProgram="setup.exe"
;!@InstallEnd@!

and called setup.sfx and add this to archive together with the other files

setup.ini
setup.exe
setup.ico
install.jar
JVM32 (folder)

but it made no difference, what else do I need to do.

Supplementary question, I also have WinRar, does it effect the end user experience whether I use 7Zip or Winrar ?

Groningen answered 12/1, 2015 at 14:41 Comment(0)
G
30

Okay I have got it working, hope this information is useful.

  1. First of all I now realize that not only do self-extracting zip start extracting with doubleclick, but they require no extraction application to be installed on the users computer because the extractor code is in the archive itself. This means that you will get a different user experience depending on what you application you use to create the sfx

  2. I went with WinRar as follows, this does not require you to create an sfx file, everything can be created via the gui:

    • Select files, right click and select Add to Archive
    • Use Browse.. to create the archive in the folder above
    • Change Archive Format to Zip
    • Enable Create SFX archive
    • Select Advanced tab
    • Select SFX Options
    • Select Setup tab
    • Enter setup.exe into the Run after Extraction field
    • Select Modes tab
    • Enable Unpack to temporary folder
    • Select text and Icon tab
    • Enter a more appropriate title for your task
    • Select OK
    • Select OK

The resultant exe unzips to a temporary folder and then starts the installer

Groningen answered 12/1, 2015 at 15:36 Comment(2)
Small caveat for using WinRAR SFX: Several security software on virustotal.com can detect it as a generic Trojan.Nameless
Did anyone come up with a solution on how to solve the security issue?Isadora
W
133

I have created step by step instructions on how to do this as I also was very confused about how to get this working.

How to make a self extracting archive that runs your setup.exe with 7zip -sfx switch

Here are the steps.

Step 1 - Setup your installation folder

To make this easy create a folder c:\Install. This is where we will copy all the required files.

Step 2 - 7Zip your installers

  1. Go to the folder that has your .msi and your setup.exe
  2. Select both the .msi and the setup.exe
  3. Right-Click and choose 7Zip --> "Add to Archive"
  4. Name your archive "Installer.7z" (or a name of your choice)
  5. Click Ok
  6. You should now have "Installer.7z".
  7. Copy this .7z file to your c:\Install directory

Step 3 - Get the 7z-Extra sfx extension module

You need to download 7zSD.sfx

  1. Download one of the LZMA packages from here
  2. Extract the package and find 7zSD.sfx in the bin folder.
  3. Copy the file "7zSD.sfx" to c:\Install

Step 4 - Setup your config.txt

I would recommend using NotePad++ to edit this text file as you will need to encode in UTF-8, the following instructions are using notepad++.

  1. Using windows explorer go to c:\Install
  2. right-click and choose "New Text File" and name it config.txt
  3. right-click and choose "Edit with NotePad++
  4. Click the "Encoding Menu" and choose "Encode in UTF-8"
  5. Enter something like this:

    ;!@Install@!UTF-8!
    Title="SOFTWARE v1.0.0.0"
    BeginPrompt="Do you want to install SOFTWARE v1.0.0.0?"
    RunProgram="setup.exe"
    ;!@InstallEnd@!
    

Edit this replacing [SOFTWARE v1.0.0.0] with your product name. Notes on the parameters and options for the setup file are here.

CheckPoint

You should now have a folder "c:\Install" with the following 3 files:

  1. Installer.7z
  2. 7zSD.sfx
  3. config.txt

Step 5 - Create the archive

These instructions I found on the web but nowhere did it explain any of the 4 steps above.

  1. Open a cmd window, Window + R --> cmd --> press enter
  2. In the command window type the following

    cd \
    cd Install
    copy /b 7zSD.sfx + config.txt + Installer.7z MyInstaller.exe
    
  3. Look in c:\Install and you will now see you have a MyInstaller.exe

  4. You are finished

Run the installer

Double click on MyInstaller.exe and it will prompt with your message. Click OK and the setup.exe will run.

P.S. Note on Automation

Now that you have this working in your c:\Install directory I would create an "Install.bat" file and put the copy script in it.

copy /b 7zSD.sfx + config.txt + Installer.7z MyInstaller.exe

Now you can just edit and run the Install.bat every time you need to rebuild a new version of you deployment package.

Weise answered 17/6, 2015 at 15:40 Comment(9)
Thanks for this great answer. I'm trying to use this technique to bundle a node webkit app. I've ran into a problem, after extracting and successfully running the app, a few minutes after I close the app, a Program Compatibility Assistant window pops up saying "The program might not have installed correctly". Progrem: 7z Setup SFX. Publisher: Igor Pavlov... I guess it's because I'm not running an actual windows installer but rather a different executor. Can you think of a way to solve that?Lithoid
The reason SFX aren't included in the 16.x release is because its built in use the -sfx flag (or the checkbox when using the GUI) when compressing!Rodd
Note for people from the future: the SFX file has moved to the LZMA sdk. As of now, the SFX stuff is in the bin folder in the archive, and the readme is DOC/installer.txtNocuous
To ilaif: Whenever you have a Windows-Installer with the name "install.exe", "setup.exe" or "update.exe" and you do not write to the registry, then Windows comes up with "The program might not have installed correctly". Solution: Rename your Installer and avoid the words install/setup/update. E.g. rename your Installer to inst.exe and everything works fine. I tested this on Windows 7.Ambassador
can I replace static folder name with Appdata under windows ?Bartender
EXCELLENT step-by-step tutorial. Do not understand why OP did not except this as excepted answer. As @script'n'code pointed out, using WinRar is not a good choice...Karelian
@Karelian ,the answer came 6 months after my own answer and by then I had settled on WinRar, but also from memory the interface provided to end user by 7zip installer when installing was uglier than the WInRar versionGroningen
My bad @paul-taylor. Was on my small screen phone and missed the date.Karelian
I followed the steps, but when I double click on the resulting .exe file, I get an error telling me it can't find the specified setup.exe file.Showpiece
G
30

Okay I have got it working, hope this information is useful.

  1. First of all I now realize that not only do self-extracting zip start extracting with doubleclick, but they require no extraction application to be installed on the users computer because the extractor code is in the archive itself. This means that you will get a different user experience depending on what you application you use to create the sfx

  2. I went with WinRar as follows, this does not require you to create an sfx file, everything can be created via the gui:

    • Select files, right click and select Add to Archive
    • Use Browse.. to create the archive in the folder above
    • Change Archive Format to Zip
    • Enable Create SFX archive
    • Select Advanced tab
    • Select SFX Options
    • Select Setup tab
    • Enter setup.exe into the Run after Extraction field
    • Select Modes tab
    • Enable Unpack to temporary folder
    • Select text and Icon tab
    • Enter a more appropriate title for your task
    • Select OK
    • Select OK

The resultant exe unzips to a temporary folder and then starts the installer

Groningen answered 12/1, 2015 at 15:36 Comment(2)
Small caveat for using WinRAR SFX: Several security software on virustotal.com can detect it as a generic Trojan.Nameless
Did anyone come up with a solution on how to solve the security issue?Isadora
K
2

It's simple with open source 7zip SFX-Packager - easy way to just "Drag & drop" folders onto it, and it creates a portable/self-extracting package.

Khachaturian answered 13/4, 2018 at 10:52 Comment(1)
Link has expired. Ther is new link (7-ZIP SFX Maker) - sourceforge.net/projects/sfx-maker/files/latest/downloadShavon

© 2022 - 2024 — McMap. All rights reserved.