Extract windows self extracting archive

7zip Self Extracting Archive (SFX) and .Net Installer

I am trying to create a self extracting archive for a windows application I have written. My app uses the latest .Net 4.0, and I want to include the .Net setup in the SFX installer. However, if the computer needs to install the .Net framework and reboot, it won’t properly resume installing my application. I looked through the other sfx posts on the Stack sites, but none of them are problems involving a .Net installer as a prerequisite for the app.

My project produces 4 files: «App Installer.msi» «setup.exe» «WindowsInstaller-KB893803-v2-x86.exe» (in the folder «WindowsInstaller3_1») and «dotNetFx40_Client_x86_x64.exe» (in the folder «DotNetFX40Client»), all of which I believe is standard.

I use 7zip to create the SFX as follows:

First, use 7zip to compress all of the files into a single archive:

Next, I do a binary copy with the 7zS.sfx file (used to create a self extracting installer), my config file, and the archive. The config file is as follows:

And I copy them with the line:

The installer works perfectly on computers which already have .Net 4.0 My problem arises on computers which don’t have the .Net Framework — I run the SFX, it extracts everything to a temp directory. Then, when setup.exe recognizes that the computer doesn’t have .Net 4.0, it calls the .Net Installer. This extracts to its own temp directory and begins installing. On completion, it prompts for a reboot. Hitting «No» exits the entire install. Hitting «Yes» reboots the machine, and on logging back in there is an error: «An error occurred trying to install MyApp» with details of «Unable to locate application file ‘App Installer.msi’

It appears that the problem is, when the installer hands off to the .Net installer, and the .Net installer reboots, the temp directory containing the My App install files is deleted. I have tried switching from setup.exe to using «App Installer.msi,» however this simply leads to the msi reporting that the computer doesn’t have .Net and suggesting a web download. As I may be installing the app in offline situations, this won’t work for me.

Has anyone else tried to include the .Net installer before in a 7zip SFX, and if so how did they solve it? I’d prefer to keep using 7zip if possible, but will look into other tools if necessary.

how to create self-extracting_archive ( programmatically )

So, how to do it?

How to pack files to self-extracting_archive. What is algorithm?

3 Answers 3

You can create self-extracting archives for windows with 7-zip, if you want to create them programmatically you can use the SDK.

If you’re more interested in ways to implement this yourself: you could have a statically linked application which has the compressed data linked into the executable (as a resource, for instance — for smaller archives a plain static const char data[] array might be sufficient). At runtime, you feed the data to a decompression library which then actually extracts files.

Читайте также:  Что такое сетевой путь windows

To keep the overhead of the executable small, I’d try to use system API (e.g. plain WIndows controls on Windows) a possible so that you don’t have to link in a toolkit. Also, for the decompression, I would use bzip2 since it provides a good compromise between compression size and decompression speed. You might also want to look at minilzo since it has a smaller code footprint than bzip2 (so the executable file is smaller) and a much higher decompression speed — it doesn’t compress as well though.

A self extracting archive is just some extractor program, but instead of taking it’s data from an archive file it takes it from constants defined in the program itself. That is really something very simple at conceptual/algorithmic level.

If you don’t care about size you can have something as simple as below (exemple in python to keep it simple, an actual unarchiver will probably be a compiled program from C or C++ source):

when you run it it creates a file hello.py that is also a python executable.

But when actually creating an auto-extracting archive, you usually want the internal data to be compressed to make the whole archive as small as possible. You also want to keep the extractor program as small as possible and also as independant as possible of what is already available on the target system. and that’s where the problems really begin.

Extract windows self extracting archive

my brain dump of solutions to technical problems

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

The scenario

When you use the default Microsoft Visual Studio Installer (yes, it is back as an extension for VS 2013 – Visual studio Installer Projects Extension), the output are two files:

  1. installer.msi – the .msi installation file
  2. setup.exe – which is the bootstrap that does your pre-requisite checks

So you want to provide a download for your product from your website as a single file.

Some possible options include:

  1. Zip the two files – the user has to download a zip, extract the zip and run the setup.exe
  2. Just provide the msi file, but this by passes the pre-requisite checks which is not ideal; or
  3. Create a self extracting archive that runs, extracts the software and then calls the setup.exe

The self extracting archive option seems the best.

The problem

I wanted to use 7Zip to create the self extracting archive but I could not seem to find a simple guide that explained exactly how to do it.

I have finally worked it out and below are some detailed instructions.

How to make a self extracting archive that launches your installer after extraction

It is actually quite simple to do if you follow these easy 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 the 7z-Extra.

  1. Follow this link to go to 7zip download.
  2. You need to download the 9.20 version (as @ May-2015) as the beta does not contain the correct files.
  3. A direct download link.
  4. Extract the 7zip extra files
  5. Copy the file “7zS.sfx” to c:\Install
Читайте также:  Python open file linux

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:

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:

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
  3. Look in c:\Install and you will now see you have a MyInstaller.exe

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.

Everything is easy… once you know how. 🙂

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.

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

P.P.S. super user

If you got here from the super user article, perhaps you would like to vote my answer up 🙂
Thanks

14 thoughts on “ How to make a self extracting archive that runs your setup.exe with 7zip -sfx switch ”

Great job! Works like a charm. This is exactly what we needed.

I followed the above instructions to create MyInstaller.exe
When I run it, it asks me for an administrator password to run the setup.exe.

If I run the setup.exe directly, it does not ask for Administrator password. Any clues how can I get around this?

Hi Jakes, I don’t have this problem? Try installing PatchCleaner from my website, PatchCleaner. This was created in this exact manner. Are you sure the file is not blocked? Right click >> Properties and sometimes you will see a “Unblock” button?

thank you for the walkthrough.
Creating the package works but it will be a 32-bit executable. I use a x64 system to create and also to distribute. Some commands don’t work if run as 32-bit-application.

Is there an option to create a 64-bit-executable

Hi
I installed the software on my computer (and Indoos 8.1) and the software not let me click on the Delete button in any way
How do I fix this?
Thank you!.

Did it find anything to remove?

If there is nothing to remove then it would not allow you to click delete.

Do the other buttons on the program work? Just wondering if it is a general UI issue or just a problem with the Delete action.

I forgot to say that I’m talking of course about the PatchCleaner.

I am also facing the same problem. I tried PatchCleaner EXE as well, that too asked for administrator password.

Is there a way to bypass that?

7z SFX file has been moved to LZMA Package. http://www.7-zip.org/a/lzma1604.7z

@Chuck
These days, it looks to me like you need to go here https://www.7-zip.org/sdk.html

Confirmed. It works

Great work. thank you so much for sharing such information.

Hi It is not working in windows-2019. The package MSI not extracting.
The same is working in wondows 10, any clue plz…

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How do I silently install a 7-zip self-extracting archive to a specific directory?

The Ruby Devkit is a 7-zip based self-extracting archive.

I would like to invoke it silently without having to install 7-Zip to extract the files to a folder of my choosing, so that I can script the installation. I imagine it to be something like:

But that, of course, doesn’t work. What command line flags must I use to silently extract this archive into a folder of my choice?

4 Answers 4

Update 2017: The tool from 7zsfx.info is now dead and gone.

Original, old post from 08-2015:

If you are trying to extract an 7zip SFX (http://7zsfx.info/) archive:

sfx.exe -y -gm2 -InstallPath=»C:\\your\\target\\path»

  • -y hide some prompts
  • -gm2 hides the extraction dialog completely (silent mode)
  • -InstallPath sets the target path (you need double backslashes)

7z SFX Guide

The official way to create a SFX package is to use -sfx[] : Create SFX archive .

And that means the created SFX packages uses two kinds of CLI options:

    official CLI options from 7zSFX, and

the passed through options you configured in your config, before creating the package.

You can think of it as parameter forwarding to the packaged executable. This parameter forwarding depends on the SetEnvironment and RunProgramm configuration!

About generate self-extracting exe with Winrar

I have to admit that I have been blocked by this problem a couple of days.

It was started with that I was looking for a tool to generate an installation exe that could pack some programs developed by me and some third-part programs developed by others into one and it also could trigger a script after installation is completed. And, I tested a lot of MSI tools but all of them not good as Win-rar which has a feature called self-extracting to handle that. It works perfectly but in order to compatible with 32bit and 64bit operating system it generates two separated exe(s) that one for 32bit and another one for 64bit.

It makes no sense because all programs inside work well in both operating systems.

Is there possible to have only one self-extracting exe that works in both environments?

Thanks for reading this and with you all have a good day.

1 Answer 1

It is a little bit late 4 months after your question to answer it, but perhaps you are still interested in an answer.

If all applications packed into the SFX archive are 32-bit applications, it does not make sense to create a 64-bit SFX archive. The 32-bit SFX archive is enough to install the applications on 32-bit and 64-bit Windows operating systems.

Which version of WinRAR do have installed? 32-bit or 64-bit version?

What is the command line or the procedure you use to create the SFX archive?

For details about command line switches see text file Rar.txt in program files directory of WinRAR.

For details about SFX script commands open help of WinRAR, select tab Index, enter SFX and you see SFX commands with links to pages explaining all SFX script commands. All of them can be configured also using GUI of WinRAR.

It is possible to save all options set for creating the SFX archive in a compression profile for easy execution on creating a new SFX archive for an updated application.

Читайте также:  Windows forms chart zoom
Оцените статью