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

  1. ' Windows Installer utility to manage the summary information stream
  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 database summary information methods
  5.  
  6. Option Explicit
  7.  
  8. Const msiOpenDatabaseModeReadOnly     = 0
  9. Const msiOpenDatabaseModeTransact     = 1
  10. Const msiOpenDatabaseModeCreate       = 3
  11.  
  12. Dim propList(19, 1)
  13. propList( 1,0) = "Codepage"    : propList( 1,1) = "ANSI codepage of text strings in summary information only"
  14. propList( 2,0) = "Title"       : propList( 2,1) = "Package type, e.g. Installation Database"
  15. propList( 3,0) = "Subject"     : propList( 3,1) = "Product full name or description"
  16. propList( 4,0) = "Author"      : propList( 4,1) = "Creator, typically vendor name"
  17. propList( 5,0) = "Keywords"    : propList( 5,1) = "List of keywords for use by file browsers"
  18. propList( 6,0) = "Comments"    : propList( 6,1) = "Description of purpose or use of package"
  19. propList( 7,0) = "Template"    : propList( 7,1) = "Target system: Platform(s);Language(s)"
  20. propList( 8,0) = "LastAuthor"  : propList( 8,1) = "Used for transforms only: New target: Platform(s);Language(s)"
  21. propList( 9,0) = "Revision"    : propList( 9,1) = "Package code GUID, for transforms contains old and new info"
  22. propList(11,0) = "Printed"     : propList(11,1) = "Date and time of installation image, same as Created if CD"
  23. propList(12,0) = "Created"     : propList(12,1) = "Date and time of package creation"
  24. propList(13,0) = "Saved"       : propList(13,1) = "Date and time of last package modification"
  25. propList(14,0) = "Pages"       : propList(14,1) = "Minimum Windows Installer version required: Major * 100 + Minor"
  26. propList(15,0) = "Words"       : propList(15,1) = "Source flags: 1=short names, 2=compressed, 4=network image"
  27. propList(16,0) = "Characters"  : propList(16,1) = "Used for transforms only: validation and error flags"
  28. propList(18,0) = "Application" : propList(18,1) = "Application associated with file, ""Windows Installer"" for MSI"
  29. propList(19,0) = "Security"    : propList(19,1) = "0=Read/write 1=Readonly recommended 2=Readonly enforced"
  30.  
  31. Dim iArg, iProp, property, value, message
  32. Dim argCount:argCount = Wscript.Arguments.Count
  33. If argCount > 0 Then If InStr(1, Wscript.Arguments(0), "?", vbTextCompare) > 0 Then argCount = 0
  34. If (argCount = 0) Then
  35.     message = "Windows Installer utility to manage summary information stream" &_
  36.         vbNewLine & " 1st argument is the path to the storage file (installer package)" &_
  37.         vbNewLine & " If no other arguments are supplied, summary properties will be listed" &_
  38.         vbNewLine & " Subsequent arguments are property=value pairs to be updated" &_
  39.         vbNewLine & " Either the numeric or the names below may be used for the property" &_
  40.         vbNewLine & " Date and time fields use current locale format, or ""Now"" or ""Date""" &_
  41.         vbNewLine & " Some properties have specific meaning for installer packages"
  42.     For iProp = 1 To UBound(propList)
  43.         property = propList(iProp, 0)
  44.         If Not IsEmpty(property) Then
  45.             message = message & vbNewLine & Right(" " & iProp, 2) & "  " & property & " - " & propLIst(iProp, 1)
  46.         End If
  47.     Next
  48.     message = message & vbNewLine & vbNewLine & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  49.  
  50.     Wscript.Echo message
  51.     Wscript.Quit 1
  52. End If
  53.  
  54. ' Connect to Windows Installer object
  55. On Error Resume Next
  56. Dim installer : Set installer = Nothing
  57. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : If CheckError("MSI.DLL not registered") Then Wscript.Quit 2
  58.  
  59. ' Evaluate command-line arguments and open summary information
  60. Dim cUpdate:cUpdate = 0 : If argCount > 1 Then cUpdate = 20
  61. Dim sumInfo  : Set sumInfo = installer.SummaryInformation(Wscript.Arguments(0), cUpdate) : If CheckError(Empty) Then Wscript.Quit 2
  62.  
  63. ' If only package name supplied, then list all properties in summary information stream
  64. If argCount = 1 Then
  65.     For iProp = 1 to UBound(propList)
  66.         value = sumInfo.Property(iProp) : CheckError(Empty)
  67.         If Not IsEmpty(value) Then message = message & vbNewLine & Right(" " & iProp, 2) & "  " &  propList(iProp, 0) & " = " & value
  68.     Next
  69.     Wscript.Echo message
  70.     Wscript.Quit 0
  71. End If
  72.  
  73. ' Process property settings, combining arguments if equal sign has spaces before or after it
  74. For iArg = 1 To argCount - 1
  75.     property = property & Wscript.Arguments(iArg)
  76.     Dim iEquals:iEquals = InStr(1, property, "=", vbTextCompare) 'Must contain an equals sign followed by a value
  77.     If iEquals > 0 And iEquals <> Len(property) Then
  78.         value = Right(property, Len(property) - iEquals)
  79.         property = Left(property, iEquals - 1)
  80.         If IsNumeric(property) Then
  81.             iProp = CLng(property)
  82.         Else  ' Lookup property name if numeric property ID not supplied
  83.             For iProp = 1 To UBound(propList)
  84.                 If propList(iProp, 0) = property Then Exit For
  85.             Next
  86.         End If
  87.         If iProp > UBound(propList) Then Wscript.Echo "Unknown summary property name: " & property : Wscript.Quit 2
  88.         If iProp = 11 Or iProp = 12 Or iProp = 13 Then
  89.             If UCase(value) = "NOW"  Then value = Now
  90.             If UCase(value) = "DATE" Then value = Date
  91.             value = CDate(value)
  92.         End If
  93.         If iProp = 1 Or iProp = 14 Or iProp = 15 Or iProp = 16 Or iProp = 19 Then value = CLng(value)
  94.         sumInfo.Property(iProp) = value : CheckError("Bad format for property value " & iProp)
  95.         property = Empty
  96.     End If
  97. Next
  98. If Not IsEmpty(property) Then Wscript.Echo "Arguments must be in the form: property=value  " & property : Wscript.Quit 2
  99.  
  100. ' Write new property set. Note! must write even if error, else entire stream will be deleted
  101. sumInfo.Persist : If CheckError("Error persisting summary property stream") Then Wscript.Quit 2
  102. Wscript.Quit 0
  103.  
  104.  
  105. Function CheckError(message)
  106.     If Err = 0 Then Exit Function
  107.     If IsEmpty(message) Then message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  108.     If Not installer Is Nothing Then
  109.         Dim errRec : Set errRec = installer.LastErrorRecord
  110.         If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  111.     End If
  112.     Wscript.Echo message
  113.     CheckError = True
  114.     Err.Clear
  115. End Function
  116.