Dan
Posts: 4484
Joined: Wed Apr 24, 2013 3:51 pm

Trigger MSI installation from a MSIX package using PowerShell

Thu Dec 12, 2019 3:38 pm

Hello,

The MSIX has limitation, no news here. In case you want to migrate the current supported features to MSIX and install the unsuported features from MSI (e.g. drivers) and have a single distribution package as MSIX then it is possible. You can include the MSI in the MSIX and trigger the MSI installation when launching the application.

The main benefit is that you will have a single setup package that will be distributed as MSIX.

Since you are in PowerShell, then you can easily have checking mechanism to see if the MSI was properly installed. For example, the following script is checking for a registry key to see if the MSI is installed and incase it is not, then it will trigger the MSI installation. The MSIX app will not be launched until the MSI is installed.

No complex mechanism was added e.g. to check the return code of the MSI to make sure that the installation was successfully but feel free to add it.

Code: Select all

$workingPath = Get-Location

#Display current location for debugging purposes
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.MessageBox]::Show("The path where MSI will be launched from: " + $workingPath)


#check if MSI was installed

$isInstalled = Test-Path -Path "HKLM:\Software\Wow6432Node\Caphyon Sample\MyApp MSI"


if (!$isInstalled){
    
    [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
    [System.Windows.Forms.MessageBox]::Show("The required MSI is missing and it will be installed. The MSIX app will be launched only after MSI installation is finished !")
    Start-Process "msiexec.exe" -Argument "/i `"$workingPath\MyApp MSIX - Copy.msi`"  /qr" -Verb RunAs -Wait

}else{
    [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
    [System.Windows.Forms.MessageBox]::Show("The required MSI is already installed. The MSIX app will be launched!")
}

To execute the powershell script you can go in the AppCompat view under the Universal Windows section. Note that Universal Windows section is automatically added in the Left view once a MSIX build type is added in the Build page.

PowerShell props - AppCompat view.PNG
PowerShell props - AppCompat view.PNG (106.57 KiB) Viewed 5844 times

My MSIX app is very simple, it contains a Win32 app and the MSI package that will be installed when the powershell script is executed, in this case each time the user will launch the application.

Files and Folders - files from MSIX package.PNG
Files and Folders - files from MSIX package.PNG (97.63 KiB) Viewed 5844 times
Please note that you need to create a different project for the MSI. For example, the MSI contained by the MSIX package will install a single file (updater.exe), no other changes will be made on the machine during intallation.

As you may know, to be able to install the MSIX package you need to sign the package. For testing purposes, I've attached a test certificate. You need to add the certificate to the Trusted Root Cerification Authorities section from the local machine. For more details, please check the Digital Signature -> Trusting a selft signed certificate article.

The sample project is attached to this thread, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.

Let us know if this may be a viable approach for you, to kick the MSI installation during a MSIX deployment.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Dan
Posts: 4484
Joined: Wed Apr 24, 2013 3:51 pm

Re: Trigger MSI installation from a MSIX package using PowerShell

Thu Jan 16, 2020 11:56 am

The Running PowerShell scripts in MSIX video shows how you can configure the MSIX package to run PowerShell scripts during MSIX deployment.

If you have used this approach please let us know what was your scenario.
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Sample Projects”