Editing MSI Property (VB.NET) - Can't Move File after Edit...
Hi all,
I've been searching the net for a solution to this one, but can't get anything to work - not that I found many related posts.
I have an installer database that I copy, edit a property in that copy, and then wish to move to another location. All appears good until I attempt to move the modified file. Its still in use. ??
Here's my code...
Dim oInstaller As WindowsInstaller.Installer
Dim oDb As WindowsInstaller.Database
Dim oView As WindowsInstaller.View = Nothing
Try
oInstaller = CType(CreateObject("WindowsInstaller.Installer"), WindowsInstaller.Installer)
oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller" & c.Tag & ".msi", 1)
oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER
oView.Execute()
oDb.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not oView Is Nothing Then
oView.Close()
End If
oDb = Nothing
oView = Nothing
oInstaller = Nothing
End Try
Is there some other closing statement of some sort I need to utilize. I've seen a post indicating that the Finally block should take care of it, but no go.
This whole thing is wrapped in a loop that cycles through some text boxes that holds the value of the Property (C.Text), referenced by the controls tag and used in the file name, C.Tag.
Thanks in advance for any feedback!!
Answers (8)
The .Dispose method does not appear to be available to me.
Session method won't work as I'm not doing this at actual install time.
Garbage collection didn't work either.
Comments:
-
Can you move "end try" 3 steps up and then try with System.GC.Collect() at the end - jagadeish 9 years ago
GC still not working for me and I don't get the .dispose method on the database object as well.
Maybe I should re-paste my current code as its changed a bit. There's a bunch of stuff commented out and the Marshal statements still are in operation.
Is there any harm in using the Marshal statements as they seem to be working.
Dim oInstaller As WindowsInstaller.Installer
Dim oDb As WindowsInstaller.Database
Dim oView As WindowsInstaller.View = Nothing
oInstaller = CType(CreateObject("WindowsInstaller.Installer"), WindowsInstaller.Installer)
oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller_" & c.Tag & ".msi", 1)
oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'")
oView.Execute()
oDb.Commit()
' The following needed for proper file closure
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oView)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oDb)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oInstaller)
''Close Not needed due to Marshal above
'If Not oView Is Nothing Then
' oView.Close()
'End If
'' Not sure if this needed any longer...
'oView = Nothing
'oDb = Nothing
'oInstaller = Nothing
'System.GC.Collect()
Dim oInstaller As WindowsInstaller.Installer
Dim oDb As WindowsInstaller.Database
Dim oView As WindowsInstaller.View = Nothing
Try
oInstaller = CType(CreateObject("WindowsInstaller.Installer"),WindowsInstaller.Installer)
oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller_" & c.Tag & ".msi", 1)
sSQL = "UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'"
oView = oDb.OpenView(sSQL)
oView.Execute()
oDb.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not (oView Is Nothing) Then
oView.Close()
End If
oView = Nothing
oDb = Nothing
oInstaller = Nothing
End Try
Should be
oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'")
Hope this is typo - jagadeish 9 years ago