Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.6 KiB

  1. ' Windows Installer database table export for use with Windows Scripting Host
  2. ' Copyright (c) 1999, Microsoft Corporation
  3. ' Demonstrates the use of the Database.Export method and MsiDatabaseExport API
  4. '
  5. Option Explicit
  6. Const msiOpenDatabaseModeReadOnly = 0
  7. Dim shortNames:shortNames = False
  8. Dim argCount:argCount = Wscript.Arguments.Count
  9. Dim iArg:iArg = 0
  10. If (argCount < 3) Then
  11. Wscript.Echo "Windows Installer database table export utility" &_
  12. vbNewLine & " 1st argument is path to MSI database (installer package)" &_
  13. vbNewLine & " 2nd argument is path to folder to contain the exported table(s)" &_
  14. vbNewLine & " Subseqent arguments are table names to export (case-sensitive)" &_
  15. vbNewLine & " Specify '*' to export all tables, including _SummaryInformation" &_
  16. vbNewLine & " Specify /s or -s anywhere before table list to force short names"
  17. Wscript.Quit 1
  18. End If
  19. On Error Resume Next
  20. Dim installer : Set installer = Nothing
  21. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  22. Dim database : Set database = installer.OpenDatabase(NextArgument, msiOpenDatabaseModeReadOnly) : CheckError
  23. Dim folder : folder = NextArgument
  24. Dim table, view, record
  25. While iArg < argCount
  26. table = NextArgument
  27. If table = "*" Then
  28. Set view = database.OpenView("SELECT `Name` FROM _Tables")
  29. view.Execute : CheckError
  30. Do
  31. Set record = view.Fetch : CheckError
  32. If record Is Nothing Then Exit Do
  33. table = record.StringData(1)
  34. Export table, folder : CheckError
  35. Loop
  36. Set view = Nothing
  37. table = "_SummaryInformation" 'not an actual table
  38. Export table, folder : Err.Clear ' ignore if no summary information
  39. Else
  40. Export table, folder : CheckError
  41. End If
  42. Wend
  43. Wscript.Quit(0)
  44. Sub Export(table, folder)
  45. Dim file : If shortNames Then file = Left(table, 8) & ".idt" Else file = table & ".idt"
  46. database.Export table, folder, file
  47. End Sub
  48. Function NextArgument
  49. Dim arg, chFlag
  50. Do
  51. arg = Wscript.Arguments(iArg)
  52. iArg = iArg + 1
  53. chFlag = AscW(arg)
  54. If (chFlag = AscW("/")) Or (chFlag = AscW("-")) Then
  55. chFlag = UCase(Right(arg, Len(arg)-1))
  56. If chFlag = "S" Then
  57. shortNames = True
  58. Else
  59. Wscript.Echo "Invalid option flag:", arg : Wscript.Quit 1
  60. End If
  61. Else
  62. Exit Do
  63. End If
  64. Loop
  65. NextArgument = arg
  66. End Function
  67. Sub CheckError
  68. Dim message, errRec
  69. If Err = 0 Then Exit Sub
  70. message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  71. If Not installer Is Nothing Then
  72. Set errRec = installer.LastErrorRecord
  73. If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  74. End If
  75. Wscript.Echo message
  76. Wscript.Quit 2
  77. End Sub