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

  1. ' Windows Installer utility to preview dialogs from a install database
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. ' Demonstrates the use of preview APIs
  5. '
  6. Option Explicit
  7.  
  8. Const msiOpenDatabaseModeReadOnly = 0
  9.  
  10. ' Show help if no arguments or if argument 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 utility to preview dialogs from an install database." &_
  15.         vbLf & " The 1st argument is the path to an install database, relative or complete path" &_
  16.         vbLf & " Subsequent arguments are dialogs to display (primary key of Dialog table)" &_
  17.         vbLf & " To show a billboard, append the Control name (Control table key) and Billboard" &_
  18.         vbLf & "       name (Billboard table key) to the Dialog name, separated with colons." &_
  19.         vbLf & " If no dialogs specified, all dialogs in Dialog table are displayed sequentially" &_
  20.         vblf &_
  21.         vblf & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  22.     Wscript.Quit 1
  23. End If
  24.  
  25. ' Connect to Windows Installer object
  26. REM On Error Resume Next
  27. Dim installer : Set installer = Nothing
  28. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  29.  
  30. ' Open database
  31. Dim databasePath : databasePath = Wscript.Arguments(0)
  32. Dim database : Set database = installer.OpenDatabase(databasePath, msiOpenDatabaseModeReadOnly) : CheckError
  33.  
  34. ' Create preview object
  35. Dim preview : Set preview = Database.EnableUIpreview : CheckError
  36.  
  37. ' Get properties from Property table and put into preview object
  38. Dim record, view : Set view = database.OpenView("SELECT `Property`,`Value` FROM `Property`") : CheckError
  39. view.Execute : CheckError
  40. Do
  41.     Set record = view.Fetch : CheckError
  42.     If record Is Nothing Then Exit Do
  43.     preview.Property(record.StringData(1)) = record.StringData(2) : CheckError
  44. Loop
  45.  
  46. ' Loop through list of dialog names and display each one
  47. If argCount = 1 Then ' No dialog name, loop through all dialogs
  48.     Set view = database.OpenView("SELECT `Dialog` FROM `Dialog`") : CheckError
  49.     view.Execute : CheckError
  50.     Do
  51.         Set record = view.Fetch : CheckError
  52.         If record Is Nothing Then Exit Do
  53.         preview.ViewDialog(record.StringData(1)) : CheckError
  54.         Wait
  55.     Loop
  56. Else ' explicit dialog names supplied
  57.     Set view = database.OpenView("SELECT `Dialog` FROM `Dialog` WHERE `Dialog`=?") : CheckError
  58.     Dim paramRecord, argNum, argArray, dialogName, controlName, billboardName
  59.     Set paramRecord = installer.CreateRecord(1)
  60.     For argNum = 1 To argCount-1
  61.         dialogName = Wscript.Arguments(argNum)
  62.         argArray = Split(dialogName,":",-1,vbTextCompare)
  63.         If UBound(argArray) <> 0 Then  ' billboard to add to dialog
  64.             If UBound(argArray) <> 2 Then Fail "Incorrect billboard syntax, must specify 3 values"
  65.             dialogName    = argArray(0)
  66.             controlName   = argArray(1) ' we could validate that controlName is in the Control table
  67.             billboardName = argArray(2) ' we could validate that billboard is in the Billboard table
  68.         End If
  69.         paramRecord.StringData(1) = dialogName
  70.         view.Execute paramRecord : CheckError
  71.         If view.Fetch Is Nothing Then Fail "Dialog not found: " & dialogName
  72.         preview.ViewDialog(dialogName) : CheckError
  73.         If UBound(argArray) = 2 Then preview.ViewBillboard controlName, billboardName : CheckError
  74.         Wait
  75.     Next
  76. End If
  77. preview.ViewDialog ""  ' clear dialog, must do this to release object deadlock
  78.  
  79. ' Wait until user input to clear dialog. Too bad there's no function to wait for keyboard input
  80. Sub Wait
  81.     Dim shell : Set shell = Wscript.CreateObject("Wscript.Shell")
  82.     MsgBox "Next",0,"Drag me away"
  83. End Sub
  84.  
  85. Sub CheckError
  86.     Dim message, errRec
  87.     If Err = 0 Then Exit Sub
  88.     message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  89.     If Not installer Is Nothing Then
  90.         Set errRec = installer.LastErrorRecord
  91.         If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
  92.     End If
  93.     Fail message
  94. End Sub
  95.  
  96. Sub Fail(message)
  97.     Wscript.Echo message
  98.     Wscript.Quit 2
  99. End Sub
  100.