Leaked source code of windows server 2003
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.

86 lines
2.8 KiB

  1. ' Windows Installer database table export for use with Windows Scripting Host
  2. ' Copyright (c) 1999-2000, 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. vbNewLine &_
  18. vbNewLine & " Copyright (C) Microsoft Corporation, 1999-2000. All rights reserved."
  19. Wscript.Quit 1
  20. End If
  21. On Error Resume Next
  22. Dim installer : Set installer = Nothing
  23. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  24. Dim database : Set database = installer.OpenDatabase(NextArgument, msiOpenDatabaseModeReadOnly) : CheckError
  25. Dim folder : folder = NextArgument
  26. Dim table, view, record
  27. While iArg < argCount
  28. table = NextArgument
  29. If table = "*" Then
  30. Set view = database.OpenView("SELECT `Name` FROM _Tables")
  31. view.Execute : CheckError
  32. Do
  33. Set record = view.Fetch : CheckError
  34. If record Is Nothing Then Exit Do
  35. table = record.StringData(1)
  36. Export table, folder : CheckError
  37. Loop
  38. Set view = Nothing
  39. table = "_SummaryInformation" 'not an actual table
  40. Export table, folder : Err.Clear ' ignore if no summary information
  41. Else
  42. Export table, folder : CheckError
  43. End If
  44. Wend
  45. Wscript.Quit(0)
  46. Sub Export(table, folder)
  47. Dim file : If shortNames Then file = Left(table, 8) & ".idt" Else file = table & ".idt"
  48. database.Export table, folder, file
  49. End Sub
  50. Function NextArgument
  51. Dim arg, chFlag
  52. Do
  53. arg = Wscript.Arguments(iArg)
  54. iArg = iArg + 1
  55. chFlag = AscW(arg)
  56. If (chFlag = AscW("/")) Or (chFlag = AscW("-")) Then
  57. chFlag = UCase(Right(arg, Len(arg)-1))
  58. If chFlag = "S" Then
  59. shortNames = True
  60. Else
  61. Wscript.Echo "Invalid option flag:", arg : Wscript.Quit 1
  62. End If
  63. Else
  64. Exit Do
  65. End If
  66. Loop
  67. NextArgument = arg
  68. End Function
  69. Sub CheckError
  70. Dim message, errRec
  71. If Err = 0 Then Exit Sub
  72. message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  73. If Not installer Is Nothing Then
  74. Set errRec = installer.LastErrorRecord
  75. If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  76. End If
  77. Wscript.Echo message
  78. Wscript.Quit 2
  79. End Sub