# XFA uninstall for MDM (Intune Win32 app / Configuration Manager Application). # # Runs in the signed-in user's context, because XFA installs per user. XFA # regenerates its MSI product code on every self-update, so the uninstall cannot # name a fixed product code or the original MSI. # # Resolve the current product through Windows Installer by XFA's stable # UpgradeCode instead of reading the registry. RelatedProducts is view-agnostic, # so it works whether the install is 32-bit (the x86 XFA.msi on x64) or 64-bit # (after the x64-to-native-ARM64 self-update). Remove every match: an install # over an advertised release before 2.0.69 leaves that registration next to the # current one (XFA-4331). Installed ones go first: an advertised older release # refuses its own removal while a newer XFA is installed (its launch condition, # NOT WIX_DOWNGRADE_DETECTED). # # Exit code, so the MDM sees a real result: 0 when every removal succeeded, # 3010 when one needs a restart, otherwise the first failing msiexec code. That # includes a leftover advertised entry that failed after XFA itself was removed: # the MDM then reports a failure although XFA is gone, which is the honest # answer. 1 when there is nothing to remove or the lookup fails. Each removal # logs to %TEMP%\xfa-uninstall-.log; the log is deleted when it succeeds. $ErrorActionPreference = 'Stop' $upgradeCode = '{FE5FD0A4-8D39-42FD-B0DE-18EB89B7CAC4}' try { $installer = New-Object -ComObject WindowsInstaller.Installer $products = @($installer.RelatedProducts($upgradeCode)) if ($products.Count -eq 0) { exit 1 } # It is just an uninstall, plus one property that only old packages read. # They relaunch XFA from a custom action guarded on "NOT WIX_UPGRADE_DETECTED", # which passes during the uninstall itself when the product is advertised # rather than installed, and then fails that uninstall with 2753. Setting the # property switches the guard off. Nothing reads it on a removal otherwise, so # it is inert on current packages and on a normal installed product. # docs/specs/XFA-3470-windows-advertised-install-1603.md. $disarmLegacyRelaunch = 'WIX_UPGRADE_DETECTED=1' # ProductState 5 is installed, 1 advertised; installed first. A plain loop # rather than Sort-Object, so a failing lookup reaches the catch below. $installed = @() $other = @() foreach ($product in $products) { if ($installer.ProductState($product) -eq 5) { $installed += $product } else { $other += $product } } $products = $installed + $other $result = 0 foreach ($product in $products) { # A verbose log per removal, so a failure says why without a rerun. $log = Join-Path $env:TEMP "xfa-uninstall-$($product.Trim('{}')).log" $msiexec = Start-Process 'msiexec.exe' -Wait -PassThru -ArgumentList @( '/x', $product, '/qn', '/norestart', $disarmLegacyRelaunch, '/l*v', "`"$log`"" ) $code = if ($msiexec) { $msiexec.ExitCode } else { 1 } if ($code -eq 0 -or $code -eq 3010) { Remove-Item -LiteralPath $log -ErrorAction SilentlyContinue if ($code -eq 3010 -and $result -eq 0) { $result = 3010 } } elseif ($result -eq 0 -or $result -eq 3010) { $result = $code } } exit $result } catch { # Fail closed: a lookup or launch failure exits non-zero, never a false success. [Console]::Error.WriteLine("XFA uninstall: $($_.Exception.Message)") exit 1 }