Release my MSI-file

PaulZ

Active member
Joined
Apr 8, 2004
Messages
26
Location
Dordrecht, the Netherlands
In my program I check the version of the MSI-file that belongs to my program.
When it has changed, I must do an update. So far so good.
But:
I read the version with the following code:
-- begin ---
Sub Check
Dim installer
installer = CreateObject("WindowsInstaller.Installer")
Dim db As WindowsInstaller.Database
Dim dbView As WindowsInstaller.View
Dim vwRecord As WindowsInstaller.Record
Dim vwSQL As String

db = installer.OpenDatabase(MsiPath, 0) MsiPath = network-msi, 0=readonly
vwSQL = "SELECT Value FROM Property WHERE Property = ProductVersion"
dbView = db.OpenView(vwSQL)
dbView.Execute()

vwRecord = dbView.Fetch
InstallerVersion = Trim(vwRecord.StringData(1)) & ".00000" InstallerVersion = a global variable
vwRecord = Nothing
dbView.Close()
dbView = Nothing
db = Nothing
installer = Nothing
End Sub
-- end --
Problem:
As soon as the installer.OpenDatabase statement is done, a network-lock is set at the msi-file telling me that I have that file opened.
After the end of the sub, I expect the msi-file to be released, but that is not the case. It is only released when my program ends. Because my program always runs (and always has the lock on the msi), I can not copy a newer msi to the network (msi already in use by ...).
You might say, stop your program and do the copy, but I am not the only user of my program (about 250 users) and I cant stop all of them.

Does anyone have an idea how to release the msi at the end of the sub?

Thanks in advance,
Paul
 
By accident I ran into another option: using API-calls (they are in a separate class MsiClass):
Sub Check()
Dim szPersist As New IntPtr(0)
Dim hDatabase As IntPtr
Dim szSelect As String = "SELECT Value FROM Property WHERE Property = ProductVersion"
Dim hView As IntPtr
Dim hRecord As IntPtr
Dim Result As Integer
Dim szBuffer As String
Dim BufLen As Integer

Result = MsiClass.MsiOpenDatabase(MsiPath, szPersist, hDatabase)
If Result = 0 Then
Result = MsiClass.MsiDatabaseOpenView(hDatabase, szSelect, hView) causes the hanging network-lock
Result = MsiClass.MsiViewExecute(hView, hRecord)
Result = MsiClass.MsiViewFetch(hView, hRecord)
szBuffer = New String(CChar(" "), 250)
BufLen = szBuffer.Length
Result = MsiClass.MsiRecordGetString(hRecord, 1, szBuffer, BufLen)
InstallerVersion = Trim(Microsoft.VisualBasic.Left(szBuffer, BufLen)) & ".00000"
Result = MsiClass.MsiViewClose(hView)
Result = MsiClass.MsiCloseHandle(hDatabase)
Result = MsiClass.MsiCloseAllHandles()
End If
End Sub

The command Result = MsiClass.MsiCloseAllHandles() closes the open handles and frees the network-lock.

Moderator can close this thread.
 
Back
Top