/build/static/layout/Breadcrumb_cap_w.png

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!!


1 Comment   [ + ] Show comment
  • oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER


    Should be

    oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'")

    Hope this is typo - jagadeish 8 years ago

Answers (8)

Posted by: anonymous_9363 8 years ago
Red Belt
0
Try adding the .Dispose method after the .Close statement.

Note that every view must be closed in order to avoid leaving open handles.

Personally, I'd be creating a transform rather than messing with MSIs in this way.
Posted by: EdT 8 years ago
Red Belt
0
Or use the Session.Database method to directly update the tables on the fly.
Posted by: jagadeish 8 years ago
Red Belt
0
You have to set the object to nothing and inform the .NET garbage collection to collect any objects no longer in use (set to nothing). 

For Example:

oInstaller = Nothing
System.GC.Collect()
Posted by: Superfreak3 8 years ago
2nd Degree Black Belt
0

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 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
0
Maybe my memory's failing me...perhaps it's the database object that needs to have the .Dispose method applied...
Posted by: Superfreak3 8 years ago
2nd Degree Black Belt
0

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()

Posted by: jagadeish 8 years ago
Red Belt
0
Can you try with this


    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
Posted by: Superfreak3 8 years ago
2nd Degree Black Belt
0
Nope!  Same Error!!
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ