On-Demand MSI customization using Azure Functions

This post describes how you can use the WIX Toolkit or any DLL file in an Azure Function, in this case to edit an MSI file on the fly. The WIX Toolkit is free, but only runs on Windows. Azure Functions run on Windows too, isn’t that nice 🙂

So, an example use case could be my OnedriveMapper MSI file, which is installed with a configuration GUID property by an admin to customize OnedriveMapper. If that GUID was already in the MSI, no such parameter would be necessary.

Using an Azure function in a download link or http request, we could insert a GUID on the fly and create personalized MSI files on demand.

I’ll leave other applications to your imagination, let’s get started!

  1. Download the WIX toolkit (binaries)
  2. Extra Microsoft.Deployment.WindowsInstaller.dll
  3. Add it to the function files or host it at an URL somewhere. In my example, I’m hosting it at http://www.lieben.nu/wix/wix.dll
  4. Add your MSI file to your function files or host it at an URL somewhere. In my example, I’m hosting it at http://www.lieben.nu/wix/OnedriveMapper.msi
  5. Add the following code to the Azure Function:

 

$urlWix = "http://www.lieben.nu/wix/wix.dll"
$outputWix = "$Env:TEMP\wix.dll"

Invoke-WebRequest -Uri $urlWix -OutFile $outputWix
try{Add-Type -Path $outputWix}catch{$Null}
$urlOM = "http://www.lieben.nu/wix/OnedriveMapper.msi"
$outputOM = "$Env:TEMP\OnedriveMapper.msi"

Invoke-WebRequest -Uri $urlOM -OutFile $outputOM

$db = New-Object Microsoft.Deployment.WindowsInstaller.Database($outputOM,[Microsoft.Deployment.WindowsInstaller.DatabaseOpenMode]::Direct);

#Query the MSI database for the CONFIGURATION_ID property:
$query = "SELECT * FROM Property WHERE Property= 'CONFIGURATION_ID'"
[Microsoft.Deployment.WindowsInstaller.View]$res = $db.OpenView($query)
$res.Execute()
 
#Modify the data
$data = $res.Fetch()
$data.SetString("Value","79D322CF-8FBE-4DF7-BD1E-6E1E3056B6B1")
$res.Modify([Microsoft.Deployment.WindowsInstaller.ViewModifyMode]::Update,$data)
 
#And Save it
$res.Close();
$db.Dispose();

Note that your modified MSI file is now at the $outputOM path. You could, from here, archive it, send it somewhere or digest a URL.

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz