首页 > 解决方案 > 列出 msi 文件中的表?

问题描述

如何使用SQL列出MSI 文件中的表

标签: sqlwindows-installer

解决方案


MSI SDK _Tables 表是一个只读系统表,列出了数据库中的所有表。查询此表以查明表是否存在。

改编来自Windows Installer SDKWiExport.vbsWindows Installer 脚本示例中的脚本,您会得到如下所示的内容。


MSI SDK VBScripts:为了找到WiExport.vbs:安装了 Visual Studio,请查看:( %ProgramFiles(x86)%\Windows Kits\10\bin\10.0.17763.0\x86调整当前安装的版本号)(或仅在 github.com 上搜索)。


示例屏幕截图:这是以下脚本的示例运行:

在此处输入图像描述

示例:脚本程序:

  • 1)另存为ListMSITables.vbs桌面(链接到 github.com)
  • 2)将 MSI 文件拖放到 VBScript 上
  • 3)一个消息框将显示表格的数量和表格名称

注意:非常大的 MSI 文件可能会使消息框溢出屏幕。只需按任意键即可关闭(我使用ESC)。

On Error Resume Next
Const msiOpenDatabaseModeReadOnly = 0

Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Dim counter : counter = 0

' Verify incoming drag and drop arguments
If WScript.Arguments.Count = 0 Then MsgBox "Drag and drop an MSI file onto the VBScript" End If
filename = Wscript.Arguments(0)
If (Right (LCase(filename),3) <> "msi") Then 
   WScript.Quit
End If

Dim database : Set database = installer.OpenDatabase(filename, msiOpenDatabaseModeReadOnly)
Dim table, view, record

Set view = database.OpenView("SELECT `Name` FROM _Tables")
view.Execute

Do
    Set record = view.Fetch
    If record Is Nothing Then Exit Do
    table = record.StringData(1)
    tables = tables + table + vbNewLine
    counter = counter + 1
Loop

MsgBox "Number of tables: " + CStr(counter) + vbNewLine + vbNewLine + tables

Set view = Nothing

Github.com:上面显然是 VBScript。只需掠夺 github.com以获取更多相同的内容,包括各种语言。


链接:


推荐阅读