如何从msi包中提取ProductCode?

时间:2011-02-15 14:43:26

标签: windows-installer msiexec

如何从msi包中提取ProductCode?我想稍后使用它来通过msiexec卸载msi,如here

所述

3 个答案:

答案 0 :(得分:4)

我可以想到几十种方法。您目前使用和/或使用哪些编程语言?

看看

Execute SQL Statements

您可以使用WiRunSQL.vbs(在Platform SDK中提供)来运行命令:

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

答案 1 :(得分:0)

通过在PowerShell中根据已安装的程序执行以下操作,您可以获得类似的效果:

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

(Obv越严格查询,它运行得越快 - 上面的LIKE非常昂贵)

或者你可以在你的筹码上申请the general technique in here

答案 2 :(得分:0)

我编写了一个Powershell函数,该函数在工作时生成基于MSI的Chocolatey软件包时使用,以检测我们的内部软件包是否正在安装已经通过其他方式安装的程序:

def solution(data, n):
    occurrences = {}
    # count occurrences
    for item in data:
        occurrences[item] = occurrences.get(item, 0) + 1
    # return trimmed data
    data.clear()
    for k, v in occurrences.items():
        if v <= n:
            data.append(k)
    return data
相关问题