' 
' Script by Benny Levinger :-)
'

Option Explicit

Const msiOpenDatabaseModeTransact = 1

Dim oFS
Dim openMode
Dim installer
Dim databasePath
Dim database
Dim Response
Dim SQL_Query
Dim view 
Dim PropertyToChange 

openMode = msiOpenDatabaseModeTransact 

' Check if the database is present
Set oFS = CreateObject("Scripting.FileSystemObject")

databasePath = Wscript.Arguments(0)
PropertyToChange = Wscript.Arguments(1)

' Connect to Windows installer object
On Error Resume Next
Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
CheckError

' Open database
Set database = installer.OpenDatabase(databasePath, openMode)
CheckError






SQL_Query = "UPDATE Property SET Value = '" & PropertyToChange & "'  WHERE Property = 'DISPAYED_VERSION'"
Set view = database.OpenView(SQL_Query )
CheckError
view.Execute
CheckError
database.Commit


Wscript.Quit 0


'Subroutines

Sub CheckError
	Dim message, errRec
	If Err = 0 Then Exit Sub
	message = Err.Source & " " & Hex(Err) & ": " & Err.Description
	If Not installer Is Nothing Then
		Set errRec = installer.LastErrorRecord
		If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
	End If
	Fail message
End Sub

Sub Fail(message)
	Wscript.Echo message
	Wscript.Quit 2
End Sub
