Pregunta

¿Cómo extraer el código de productos del paquete MSI?Quiero usarlo más tarde para desinstalar MSI a través de MSIExec como se describe aquí

¿Fue útil?

Solución

Puedo pensar en docenas de formas de hacerlo.¿Qué lenguajes de programación usas y / o confortables actualmente?

Eche un vistazo a

Ejecutar sentencias SQL

Podría usar Wirunsql.vbs (proporcionado en la plataforma SDK) para ejecutar el comando:

cscript /nologo WiRunSQL.vbs FOO.msi "SELECT Value FROM Property WHERE Property = 'ProductCode'"

Otros consejos

Podría lograr un efecto similar al hacer lo siguiente en PowerShell basado en los programas instalados:

Get-WmiObject -Class Win32_Product -Filter "Vendor LIKE 'The Company%' AND Name LIKE '%The Product%'" | %{ 
    Write-Host "Uninstalling $($_.IdentifyingNumber)"
    $_.Uninstall() 
}

(Obvérgese cuanto más apretar la consulta, cuanto más rápido funcionará, el gusto de arriba es muy caro)

o podría aplicar la técnica general aquí en su pila.

Escribí una función de PowerShell que utilizo al generar paquetes de chocolate con sede en MSI en el trabajo, para detectar si nuestro paquete interno está instalando un programa que ya se instaló a través de otros medios:

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
}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top