GetMSIVersion: How to Check MSI Package and Installed Product Versions
Determining the version of a Microsoft Installer (MSI) file or an already installed product is a core task for system administrators and deployment engineers. Whether you are packaging an application or troubleshooting a deployment failure, you need accurate version data.
Here is a comprehensive guide to extracting MSI version information using multiple methods. 1. Checking an Uninstalled MSI File Version
To find the version of an MSI file before installing it, you must query its internal relational database. The version is stored in the Property table under the ProductVersion property. Windows PowerShell (COM Object Method)
PowerShell can access the Windows Installer COM object to read the MSI database directly without installing the software. powershell Use code with caution. Windows File Explorer Right-click the .msi file. Select Properties. Navigate to the Details tab.
Look for the Product version or Revision number field. Note that this method relies on the packager filling out the summary information stream correctly, so script-based methods are more reliable. 2. Checking an Installed MSI Product Version
If the application is already installed on the system, Windows tracks its version in the registry and via the Windows Management Instrumentation (WMI) framework. PowerShell (Get-CimInstance)
Avoid using Get-WmiObject Win32_Product, as it triggers a self-repair validation for every installed MSI, which is slow and can cause system errors. Use Get-CimInstance to read the registry-backed registry provider instead. powershell
# Replace with your application name (supports wildcards) \(appName = "*AppName*" # Retrieve installed application details safely Get-CimInstance Win32_Product | Where-Object {\).Name -like \(appName} | Select-Object Name, Version, IdentifyingNumber </code> Use code with caution. PowerShell (Registry Query Method)</p> <p>The fastest and safest way to check installed versions is by querying the Windows Registry uninstall keys directly. This bypasses WMI completely. powershell</p> <p><code>\)paths = @( “HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall*”, “HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall*” ) # Search for the application by display name Get-ItemProperty \(paths | Where-Object {\).DisplayName -like “AppName”} | Select-Object DisplayName, DisplayVersion, UninstallString Use code with caution. 3. Creating a Custom “GetMSIVersion” PowerShell Function
For convenience, you can wrap the offline MSI file viewer into a reusable advanced PowerShell function. Paste this into your profile or deployment scripts: powershell
function Get-MSIVersion { [CmdletBinding()] param( [Parameter(Mandatory=\(true, ValueFromPipeline=\)true)] [ValidateScript({Test-Path \(_})] [string]\)Path ) process { try { \(resolvedPath = (Resolve-Path \)Path).Path \(installer = New-Object -ComObject WindowsInstaller.Installer \)database = \(installer.OpenDatabase(\)resolvedPath, 0) \(view = \)database.OpenView(“SELECT Use code with caution. Usage: powershell Value FROM Property WHERE Property = ‘ProductVersion’”) \(view.Execute() \)record = \(view.Fetch() if (\)record) { [PSCustomObject]@{ MSIPath = \(resolvedPath Version = \)record.StringData(1) } } else { Write-Error “Could not find ProductVersion in \(resolvedPath" } } catch { Write-Error \)_.Exception.Message } finally { if (\(view) { \)view.Close() } if (\(database) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject(\)database) | Out-Null } if (\(installer) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject(\)installer) | Out-Null } [GC]::Collect() } } } Get-MSIVersion -Path “C:\Installers\7zip.msi” Use code with caution.
To inspect a local file, use the COM Object database query method for 100% accuracy.
To check an installed application, query the Windows Registry paths to maximize speed and prevent unwanted MSI self-repair cycles. If you want to customize this further, let me know:
What programming language or automation tool are you using? (PowerShell, C#, Python, or VBScript?)
Leave a Reply