I am trying to query a MSI to get the ProductCode from the MSI so I can later populate a script with the proper ProductCode.
During debugging it "looks" like the database is open for read, however if I look at the oDB object I see this "Error = No further information on this object could be discovered" When it tries to do the OpenView on the SQL statement it throws an exception "OpenView, Sql" I believe that is because the MSI really isn't open for read?
I have added the reference to the Microsoft Windows Installer Object Library version 1.0.0.0
Any idea what is up, I have "googled" and can't find any other useful code
Here is the code: (I pass the fully qualified path + filename of the msi)
Private Sub GetMsiProperty(ByVal sMSIFilePath As String)
Const sReadMSIDataBaseErrorStr As String = "ERROR: Could not read MSI database!"
Const msiOpenDatabaseModeReadOnly = 0
Dim oInstaller As Installer
Dim oDb As Database
Dim oView As View = Nothing
Dim oRecord As Record
Try
oInstaller = CType(CreateObject("WindowsInstaller.Installer"), Installer)
oDb = oInstaller.OpenDatabase(sMSIFilePath, msiOpenDatabaseModeReadOnly)
'"SELECT 'ProductCode' FROM 'Property'"
'"SELECT FROM 'Property' WHERE `Property`='ProductCode'"
'"SELECT `ProductCode` FROM `Property` WHERE `Property` = ProductCode"
oView = oDb.OpenView("SELECT * FROM 'Property'")
oView.Execute(oRecord)
oRecord = oView.Fetch()
While Not oRecord Is Nothing
_sGUID = oRecord.StringData(1)
End While
MessageBox.Show("This is the MSI file: " + sMSIFilePath, "")
MessageBox.Show("This is the GUID: " + _sGUID, "")
Return
Catch ex As Exception
MessageBox.Show(sReadMSIDataBaseErrorStr + ": " + ex.Message, CreatePackageDirectoryWindows_OkButtonclick_CreatePackageDir_Win_Exception___, MessageBoxButtons.OK)
Return
Finally
If Not (oView Is Nothing) Then
Marshal.FinalReleaseComObject(oView)
oView.Close()
End If
End Try
End Sub
thanks,
Steve

New Topic/Question
Reply



MultiQuote



|