Powershell获取MST信息

时间:2017-04-07 07:26:53

标签: powershell windows-installer

我必须通过应用的MST从MSI中读取一些信息。我知道如何从纯MSI读取表格,但不知道如何应用MST。

我用它来做MSI:

    Process {
    try {
        # Read property from MSI database
        $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
        $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
        $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
        # $Query = "SELECT Action FROM CustomAction WHERE Action = '$($CustomAction)'"
        $View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
        $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null) | out-null
        $Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
        try {
            $Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)

            # Commit database and close view
            $MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null) | out-null
            $View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null) | Out-Null
            $MSIDatabase = $null
            $View = $null
        } catch {
            $Value = "-"
        }
        # Return the value

        return $Value

如果有人可以帮助我,那将是非常好的!

谢谢,莫里茨:)

1 个答案:

答案 0 :(得分:0)

查看Win SDK" wilstxfm.vbs"中的示例。在我的系统上,它安装在这条路径上:

c:\Program Files (x86)\Windows Kits\8.1\bin\x64\wilstxfm.vbs

由于版权问题,无法在此处粘贴代码,但他们基本上会这样做:

database = installer.OpenDatabase(msiPath,0) 
database.ApplyTransform(mstPath, iteViewTransform + iteAddExistingRow + iteDelNonExistingRow + iteAddExistingTable + iteDelNonExistingTable + iteUpdNonExistingRow + iteChangeCodePage)
view = database.OpenView("SELECT * FROM `_TransformView` ORDER BY `Table`, `Row`")

然后,他们迭代视图的记录以打印转换所做的更改。

您应该能够将.vbs示例转换为PowerShell代码,或者只是从PS调用.vbs脚本。