Come estrarre il codice prodotto dal pacchetto MSI?
-
14-11-2019 - |
Domanda
Come estrarre il codice prodotto dal pacchetto MSI?Voglio usarlo in seguito per disinstallare MSI Via Msiexec come descritto qui
Soluzione
Posso pensare a decine di modi per farlo.Quali lingue di programmazione usi e / o comodo con?
Dai un'occhiata a
È possibile utilizzare wirunsql.vbs (fornito nella piattaforma SDK) per eseguire il comando:
cscript /nologo WiRunSQL.vbs FOO.msi "SELECT Value FROM Property WHERE Property = 'ProductCode'"
. Altri suggerimenti
È possibile ottenere un effetto simile facendo il seguente in PowerShell in base ai programmi installati:
Get-WmiObject -Class Win32_Product -Filter "Vendor LIKE 'The Company%' AND Name LIKE '%The Product%'" | %{
Write-Host "Uninstalling $($_.IdentifyingNumber)"
$_.Uninstall()
}
.
(Ovvia la query più stretta, più veloce funzionerà - l'aspetto simile è molto costoso)
o potresti applicare La tecnica generale qui sul tuo stack.
Ho scritto una funzione PowerShell che utilizzo quando si generano pacchetti di cioccolato basati su MSI al lavoro, per rilevare se il nostro pacchetto interno sta installando un programma già installato tramite altri mezzi:
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
}
.