List Tables in an msi file?

吃可爱长大的小学妹 提交于 2021-02-08 07:56:08

问题


How does one use SQL to list the tables in an MSI file?


回答1:


MSI SDK: The _Tables table is a read-only system table that lists all the tables in the database. Query this table to find out if a table exists.

Adapting the script WiExport.vbs from the Windows Installer Scripting Examples from the Windows Installer SDK you get something like the below.


MSI SDK VBScripts: In order to find WiExport.vbs: With Visual Studio installed, look under: %ProgramFiles(x86)%\Windows Kits\10\bin\10.0.17763.0\x86 (adjust version numbers for your current installation) (or just search for it on github.com).


Sample Screen Shot: Here is a sample run of the script below:

Sample: Procedure for script:

  • 1) save as ListMSITables.vbs on desktop (link to github.com)
  • 2) drag-and-drop an MSI file onto the VBScript
  • 3) a message box will show number of tables, and table names

Note: Very large MSI files could make the message box overflow the screen. Just press any key to dismiss (I use 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: The above is obviously VBScript. Just pillage github.com for more of the same, in all kinds of languages.



来源:https://stackoverflow.com/questions/58348774/list-tables-in-an-msi-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!