Create an EXE wrapper over MSIX with 7Zip SFX Maker

Although these are rares cases, you might have some scenarios where you want to modify something on the system before you install your MSIX package. One example that I’ve stumbled upon was a user who had old MSI versions installed on the machine and these left a lot of user data behind after the uninstall.

The problem was that the MSIX package let’s your application read from the required folders on the machine, meaning if you have old settings saved in %appdata%, it is possible that when you open up your MSIX package, this will read all the settings and it’s not something you would like.

One other exampled that I’ve seen is when a user had an app which was reading some settings from the HKLM registry, and he did not wanted that registry to be captured in the MSIX package, because it was dynamic on each machine and he wanted to control it via 3rd party infrastructure tools.

In both cases, there is a workaround that you can use to modify your system before installing the MSIX package, and this is PowerShell combined with 7Zip SFX Maker. You might ask…why bother to create an EXE wrapper over a PowerShell script? The answer is easy: most users don’t have a clue what PowerShell is, and they are used to see .exe files when it comes to installers.

Now, let’s see how we can create an EXE installation wrapper over an MSIX with 7ZIP SFX Maker.

Step 1: Create the PowerShell script

If you have your MSIX already prepared, you need to do the PowerShell script that installs it and modifies the system as you desire. For this example I’ve created a simple PowerShell script that deletes a folder called MyDirectory from %appdata% before installing the MSIX package. The script contents are:

$DeleteFolder = $env:APPDATA + "\MyDirectory"

Remove-Item -Path $DeleteFolder -Recurse -Force

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition

$InstallationPath = $scriptPath + "\Environment Variables Test-x64.msix"

Add-AppPackage -path $InstallationPath
We are using the $scriptPath variable to determine the location of the script in order to install the MSIX. The MSIX will be placed near the script. To install the MSIX package, we are using the Add-AppPackage PowerShell cmdlet.

Step 2: Archive the PowerShell script & MSIX Package

Now that the script is created, place the MSIX and PowerShell script near each other. Next, select them, right-click and select 7Zip > Add to archive…
In the new window that appears select the Archive format as 7z, the Compression level to Normal, the Compression Method to LZMA. Afterwards click OK and your 7z archive will be created.

Step 3: Create EXE with 7Zip SFX Maker

The MSIX package is done, the script is done, they are both archived to a specific 7z archive. The last step is to create the EXE wrapper. To do this, open 7-ZIP SFX Maker as an administrator and follow these steps:
In the Files tab, click on the Plus button and select the previously created 7z archive.
In the Dialogs > General configure a Title for the installation, set it to Overwrite all files and check Extract to temporary folder. Also you can check Show SFX icon in Begin, Finish and Cancel Prompt.
In the Dialogs > Begin Prompt tab, check Begin promp and write a desired message. In my case I wrote Start Installation?
In the Dialogs > Extract path deselect Allow user to change path. I want the archive to always be extracted in %temp%. If you want you can change this, but you must also change another step which i will get to later on.
In the Tasks tab, click on the Plus button and configure it as follows:
Program: %SystemRoot%\System32\WindowsPowershell\v1.0\powershell.exe
Arguments: -windowstyle hidden -file %%T\InstallMSIX.ps1
Also check the Hide console windows. What is happening is that we are running PowerShell from it’s installation location (on every machine is the same), and we are passing the Windowstyle hidden and File arguments. The Windowstyle hidden argument hides any PowerShell console windows that might appear, and the File argument is pointing to our previously created PowerShell script (that we added in the 7z archive).
The %%T stands for the extraction path. For more variables, right-click in the Program or Arguments fields.
As a last step, click Make SFX.
If everything was followed correctly, you should now have your EXE created. Now when you try to install it, the script and the MSIX will be extracted to a temporary location, and the PowerShell script will be executed afterwards. This makes everything very easy for the user because all he has to do is accept the installation and that is it.

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

19 − 8 =