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:
- installer.msi – the .msi installation file
- 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:
- Zip the two files – the user has to download a zip, extract the zip and run the setup.exe
- Just provide the msi file, but this by passes the pre-requisite checks which is not ideal; or
- 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
- Go to the folder that has your msi and your setup.exe
- Select both the .msi and the setup.exe
- Right-Click and choose 7Zip –> “Add to Archive”
- Name your archive “Installer.7z” (or a name of your choice)
- Click Ok
- You should now have “Installer.7z”.
- 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.
- Follow this link to go to 7zip download.
- You need to download the 9.20 version (as @ May-2015) as the beta does not contain the correct files.
- A direct download link.
- Extract the 7zip extra files
- Copy the file “7zS.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++.
- Using windows explorer go to c:\Install
- right-click and choose “New Text File” and name it config.txt
- right-click and choose “Edit with NotePad++
- Click the “Encoding Menu” and choose “Encode in UTF-8”
- Enter something like this:
[csharp]
;!@Install@!UTF-8!
Title="SOFTWARE v1.0.0.0"
BeginPrompt="Do you want to install SOFTWARE v1.0.0.0?"
RunProgram="setup.exe"
;!@InstallEnd@!
[/csharp]
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:
- Installer.7z
- 7zS.sfx
- 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.
- Open a cmd window, Window + R –> cmd –> press enter
- In the command window type the following
[csharp]
cd \
cd Install
copy /b 7zS.sfx + config.txt + Installer.7z MyInstaller.exe
[/csharp] - 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.
[csharp]
copy /b 7zS.sfx + config.txt + Installer.7z MyInstaller.exe
[/csharp]
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
Great job! Works like a charm. This is exactly what we needed.
Thnak you!
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?
Windows checks for programs called “setup” or “installer” and does an administrator prompt for them before running them.
You can either: (1) rename your installer or (2) embed an application manifest into your MyInstaller.exe file using mt.exe that has the requestedExecutionLevel set.
Hi,
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
Thank you
You need to download LZMA SDK and use 7zr.exe from x64 folder inside.
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.
@jcrawfor74
Hi,
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?
Regards
Nitin
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.
regards
lb
Hi It is not working in windows-2019. The package MSI not extracting.
The same is working in wondows 10, any clue plz…
Hi, I am not a Developer so please bare with me. Your solution for the -zip installer may be applicable to my issue, let me run this by you. I have an online Help output folder and I wish to make it an executable file that opens a specific file in the folder when the receiver executes the file. In 7-Zip’s ‘Add to Archive’ interface, I see an entry field for ‘Parameters’; can I use that space to enter a command that opens a specific file upon execution of my output exe file? More succinctly, I successfully created a SFX archive using 7-ZIP but I want the exe file to launch a specific file (e.g. Index.html) within the folder so that Help opens in full form when someone executes the output exe file. Any advice in this regard is greatly appreciated.
6/5/22
Followed all the directions but my computer security wouldn’t allow MyIntaller.exe on board. Said it had a malicious Trojan…..thanks………JT