如何从MSI包中提取ProductCode?
-
14-11-2019 - |
题
如何从MSI包中提取ProductCode?我稍后使用它来通过msiexec卸载msi,如这里
解决方案
我可以想到几十种方法来做到这一点。您目前使用哪种编程语言和/或舒适?
看看
您可以使用wireunsql.vbs(在平台SDK中提供)来运行命令:
cscript /nologo WiRunSQL.vbs FOO.msi "SELECT Value FROM Property WHERE Property = 'ProductCode'"
. 其他提示
您可以通过基于已安装的程序在PowerShell中执行以下操作来实现类似的效果:
Get-WmiObject -Class Win32_Product -Filter "Vendor LIKE 'The Company%' AND Name LIKE '%The Product%'" | %{
Write-Host "Uninstalling $($_.IdentifyingNumber)"
$_.Uninstall()
}
.
(verv the查询时,运行更快 - 就像上面的那样昂贵)
或者您可以应用这里的一般技术堆栈上。
我写了一个powershell函数,我在工作中生成基于MSI的巧克力包时使用,检测我们的内部包是否正在安装已通过其他方式安装的程序:
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
}
. 不隶属于 StackOverflow