home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / Chip_2001-06_cd1.bin / zkuste / vbasic / Data / Utility / MSISDK15.msi / WiLstScr.vbs < prev    next >
Text File  |  2000-10-05  |  2KB  |  65 lines

  1. ' Windows Installer script viewer for use with Windows Scripting Host CScript.exe only
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. ' Demonstrates the use of the special database processing mode for viewing script files
  5. '
  6. Option Explicit
  7.  
  8. Const msiOpenDatabaseModeListScript = 5
  9.  
  10. ' Check arg count, and display help if argument not present or contains ?
  11. Dim argCount:argCount = Wscript.Arguments.Count
  12. If argCount > 0 Then If InStr(1, Wscript.Arguments(0), "?", vbTextCompare) > 0 Then argCount = 0
  13. If argCount = 0 Then
  14.     Wscript.Echo "Windows Installer Script Viewer for Windows Scripting Host (CScript.exe)" &_
  15.         vbNewLine & " Argument is path to installer execution script" &_
  16.         vbNewLine &_
  17.         vbNewLine & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  18.     Wscript.Quit 1
  19. End If
  20.  
  21. ' Cannot run with GUI script host, as listing is performed to standard out
  22. If UCase(Mid(Wscript.FullName, Len(Wscript.Path) + 2, 1)) = "W" Then
  23.     Wscript.Echo "Cannot use WScript.exe - must use CScript.exe with this program"
  24.     Wscript.Quit 2
  25. End If
  26.  
  27. Dim installer, view, database, record, fieldCount, template, index, field
  28. On Error Resume Next
  29. Set installer = CreateObject("WindowsInstaller.Installer") : CheckError
  30. Set database = installer.Opendatabase(Wscript.Arguments(0), msiOpenDatabaseModeListScript) : CheckError
  31. Set view = database.Openview("")
  32. view.Execute : CheckError
  33. Do
  34.    Set record = view.Fetch
  35.    If record Is Nothing Then Exit Do
  36.    fieldCount = record.FieldCount
  37.    template = record.StringData(0)
  38.    index = InstrRev(template, "[") + 1
  39.    If (index > 1) Then
  40.       field = Int(Mid(template, index, InstrRev(template, "]") - index))
  41.       If field < fieldCount Then
  42.          template = Left(template, Len(template) - 1)
  43.          While field < fieldCount
  44.             field = field + 1
  45.             template = template & ",[" & field & "]"
  46.          Wend
  47.          record.StringData(0) = template & ")"
  48.       End If
  49.    End If
  50.    Wscript.Echo record.FormatText
  51. Loop
  52. Wscript.Quit 0
  53.  
  54. Sub CheckError
  55.     Dim message, errRec
  56.     If Err = 0 Then Exit Sub
  57.     message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  58.     If Not installer Is Nothing Then
  59.         Set errRec = installer.LastErrorRecord
  60.         If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  61.     End If
  62.     Wscript.Echo message
  63.     Wscript.Quit 2
  64. End Sub
  65.