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

  1. ' Windows Installer utility to applay a transform to an installer database
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. ' Demonstrates use of Database.ApplyTransform and MsiDatabaseApplyTransform
  5. '
  6. Option Explicit
  7.  
  8. ' Error conditions that may be suppressed when applying transforms
  9. Const msiTransformErrorAddExistingRow         = 1 'Adding a row that already exists. 
  10. Const msiTransformErrorDeleteNonExistingRow   = 2 'Deleting a row that doesn't exist. 
  11. Const msiTransformErrorAddExistingTable       = 4 'Adding a table that already exists. 
  12. Const msiTransformErrorDeleteNonExistingTable = 8 'Deleting a table that doesn't exist. 
  13. Const msiTransformErrorUpdateNonExistingRow  = 16 'Updating a row that doesn't exist. 
  14. Const msiTransformErrorChangeCodePage       = 256 'Transform and database code pages do not match 
  15.  
  16. Const msiOpenDatabaseModeReadOnly     = 0
  17. Const msiOpenDatabaseModeTransact     = 1
  18. Const msiOpenDatabaseModeCreate       = 3
  19.  
  20. If (Wscript.Arguments.Count < 2) Then
  21.     Wscript.Echo "Windows Installer database tranform application utility" &_
  22.         vbNewLine & " 1st argument is the path to an installer database" &_
  23.         vbNewLine & " 2nd argument is the path to the transform file to apply" &_
  24.         vbNewLine & " 3rd argument is optional set of error conditions to suppress:" &_
  25.         vbNewLine & "     1 = adding a row that already exists" &_
  26.         vbNewLine & "     2 = deleting a row that doesn't exist" &_
  27.         vbNewLine & "     4 = adding a table that already exists" &_
  28.         vbNewLine & "     8 = deleting a table that doesn't exist" &_
  29.         vbNewLine & "    16 = updating a row that doesn't exist" &_
  30.         vbNewLine & "   256 = mismatch of database and transform codepages" &_
  31.         vbNewLine &_
  32.         vbNewLine & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  33.     Wscript.Quit 1
  34. End If
  35.  
  36. ' Connect to Windows Installer object
  37. On Error Resume Next
  38. Dim installer : Set installer = Nothing
  39. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  40.  
  41. ' Open database and apply transform
  42. Dim database : Set database = installer.OpenDatabase(Wscript.Arguments(0), msiOpenDatabaseModeTransact) : CheckError
  43. Dim errorConditions:errorConditions = 0
  44. If Wscript.Arguments.Count >= 3 Then errorConditions = CLng(Wscript.Arguments(2))
  45. Database.ApplyTransform Wscript.Arguments(1), errorConditions : CheckError
  46. Database.Commit : CheckError
  47.  
  48. Sub CheckError
  49.     Dim message, errRec
  50.     If Err = 0 Then Exit Sub
  51.     message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  52.     If Not installer Is Nothing Then
  53.         Set errRec = installer.LastErrorRecord
  54.         If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  55.     End If
  56.     Wscript.Echo message
  57.     Wscript.Quit 2
  58. End Sub
  59.