How to extract ProductCode from msi package? I want to use it later to uninstall msi via msiexec as described here
I can think of dozens of ways to do it. What programming languages do you currently use and/or comfortable with?
Take a look at
Execute SQL Statements
You could use WiRunSQL.vbs ( provided in the Platform SDK ) to run the command:
cscript /nologo WiRunSQL.vbs FOO.msi "SELECT Value FROM Property WHERE Property = 'ProductCode'"
I wrote a Powershell function that I use when generating MSI-based Chocolatey packages at work, to detect if our internal package is installing a program that was already installed via other means:
function Get-MsiProductCode {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ValidateScript({$_ | Test-Path -PathType Leaf})]
[string]$Path
)
function Get-Property ( $Object, $PropertyName, [object[]]$ArgumentList ) {
return $Object.GetType().InvokeMember($PropertyName, 'Public, Instance, GetProperty', $null, $Object, $ArgumentList)
}
function Invoke-Method ( $Object, $MethodName, $ArgumentList ) {
return $Object.GetType().InvokeMember( $MethodName, 'Public, Instance, InvokeMethod', $null, $Object, $ArgumentList )
}
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
#http://msdn.microsoft.com/en-us/library/aa369432(v=vs.85).aspx
$msiOpenDatabaseModeReadOnly = 0
$Installer = New-Object -ComObject WindowsInstaller.Installer
$Database = Invoke-Method $Installer OpenDatabase $Path, $msiOpenDatabaseModeReadOnly
$View = Invoke-Method $Database OpenView "SELECT Value FROM Property WHERE Property='ProductCode'"
[void]( Invoke-Method $View Execute )
$Record = Invoke-Method $View Fetch
if ( $Record ) {
Get-Property $Record StringData 1
}
[void]( Invoke-Method $View Close @() )
Remove-Variable -Name Record, View, Database, Installer
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With