Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Modification of MSI database from VB6


3 replies to this topic

rgraham

rgraham
  • Members
  • 16 posts

Posted 06 November 2003 - 22:59

Hi all,

Does anyone have any experience with modification of MSI database files using queries from VB6?

Specifically, I am using the Automation interface to open a .msi file in edit mode.
( no problems there).

Then I am trying to add the text of a license agreement rtf file into the LicenseAgreementDlg textbox control. I attempt to execute an update query, but I get an error when I try to open the view.

Any suggestions?

My code looks something like this:

--------------------------------------------------------------------------------------------

'Read agreement text from specified file, open Control table and add
'the text to the AgreementText control of LicenseAgreementDlg

Sub AddLicenseAgreement(ByRef strLicenseFile As String)
Dim objView As View
Dim strLicenseText As String
Dim strSQL As String

'Get the license text from the rtf file
strLicenseText = ReadRTFFile(strLicenseFile)

'Assemble the update query string, enclosing text in single quotes
strSQL = "UPDATE Control SET Control.Text=" _
& "'" & strLicenseText & "'" _
& " WHERE Control.Dialog='LicenseAgreementDlg'" _
& " AND Control.Control='AgreementText'"

With g_MSIDatabase
'Execute the update query
Set objView = .OpenView(strSQL)

'Close the view
objView.Close

'Commit the msi database changes
.Commit

End With

End Sub

--------------------------------------------------------------------------------------------


TIA,

R

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 07 November 2003 - 02:49

Hmm, sorry I have never done anything like this. Here is some sample code that I use to update the "Upgrade" table in my database during build automation. It is very different, but maybe it gives you an idea:

CODE
Set oneWindowsInstaller = CreateObject("WindowsInstaller.Installer")
Set oneInstallerDatabase = oneWindowsInstaller.OpenDatabase("C:\BasicMSI.ism", 1)

' Set up SQL query for the upgrade table - DETECT NEWER VERSION INSTALLED
Set oneView = oneInstallerDatabase.OpenView _
    ("SELECT * FROM Upgrade WHERE ActionProperty = 'CHECKCURRENTINSTALL'")

   ' Execute the view, so its methods can be used.
   oneView.Execute

   'Fetch records
   Set oneRecordObject = oneView.Fetch

  ' Assign new values to recordset
  oneRecordObject.StringData (2) = V_MAJOR & "." & V_MINOR  & "." & V_BUILD
  oneView.Modify 4, oneRecordObject
  oneView.Close

  Set oneRecordObject = Nothing

Regards
-Stein Åsmul

rgraham

rgraham
  • Members
  • 16 posts

Posted 07 November 2003 - 19:56

Hi,

Thanks, that was very helpful. My final code is shown below.

CODE


Public Const CONTROL_TEXT_FIELD = 10   'Const for Text field index in Control Table

'Read agreement text from specified file, open Control table and add
'the text to the AgreementText control of LicenseAgreementDlg

Sub AddLicenseAgreement(ByRef strLicenseFile As String)
Dim objView As View
Dim objRecord As Record
Dim strLicenseText As String
Dim strSQL As String

   
   'Get the license text from the rtf file
   strLicenseText = ReadRTFFile(strLicenseFile)

   'Assemble the query string to retrieve the record for the AgreementText control
   strSQL = "SELECT * FROM Control WHERE Control = 'AgreementText'"

   'Open the view
   Set objView = g_MSIDatabase.OpenView(strSQL)
   With objView
       .Execute
       'Fetch the record
       Set objRecord = .Fetch
       'Replace the string with license agreement
       objRecord.StringData(CONTROL_TEXT_FIELD) = strLicenseText
       'Call the modify method to update the field
       .Modify msiViewModifyUpdate, objRecord
       'Close the view
       .Close
   End With
   
   'Commit the msi database changes
   g_MSIDatabase.Commit

End Sub



Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 07 November 2003 - 19:59

Glad to be of help, and thanks for posting your completed code! I will add it to my script repository.
Regards
-Stein Åsmul