Force msi to overwrite files
Hi, I have made a simple package that should overwrite som existing files.
exe, txt and some other files. But it does not overwrite some files, is there a way to force the msi to overwrite the files, even when a versionnumber is lower o a date is newer that the one i try to send out, i guess this is some of the problems why it doesn't overwrite the files.
any tips?
exe, txt and some other files. But it does not overwrite some files, is there a way to force the msi to overwrite the files, even when a versionnumber is lower o a date is newer that the one i try to send out, i guess this is some of the problems why it doesn't overwrite the files.
any tips?
0 Comments
[ + ] Show comments
Answers (9)
Please log in to answer
Posted by:
jonasm
18 years ago
Posted by:
Foleymon
18 years ago
Posted by:
Lillude
18 years ago
Hi,
To replace file fourcefully try using file version in the file table for the files u want to be replaced. As per Windows Installer file-versioning rules, a versioned file will overwrite an unversioned file.
So if the files you want to replace are unversioned then give some version to them and it should replace.
Lillude
To replace file fourcefully try using file version in the file table for the files u want to be replaced. As per Windows Installer file-versioning rules, a versioned file will overwrite an unversioned file.
So if the files you want to replace are unversioned then give some version to them and it should replace.
Lillude
Posted by:
cs_m_si
18 years ago
Posted by:
kpepper
15 years ago
I struggled with this for a long time. The Reinstall mode seemed to force a reinstall of the entire Net 3.5 framework, and I just wanted my application files to be overwritten. I instead used a vbscript to set the file version on all files that need to install each time. Here is a vb script that can be placed in the setup project's post build event to set the version of every file with attribute "512" to the product version. "512" is a file set as vital to your application. Microsoft's sample file versioning vbscript is the base of this program. It still has a few more variables than it needs but will give you the basic idea, and it works.
' Windows Installer utility to report or update file versions, sizes, languages
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) Microsoft Corporation. All rights reserved. - changed by pepper
' Demonstrates the access to install engine and actions
'
Option Explicit
' FileSystemObject.CreateTextFile and FileSystemObject.OpenTextFile
Const OpenAsASCII = 0
Const OpenAsUnicode = -1
' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist = 0
' FileSystemObject.OpenTextFile
Const OpenAsDefault = -2
Const CreateIfNotExist = -1
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Const msiViewModifyInsert = 1
Const msiViewModifyUpdate = 2
Const msiViewModifyAssign = 3
Const msiViewModifyReplace = 4
Const msiViewModifyDelete = 6
Const msiUILevelNone = 2
Const msiRunModeSourceShortNames = 9
Const msidbFileAttributesNoncompressed = &h00002000
Dim message1
Dim databasePath : databasePath = "H:\active\claim_master_work\wv2008\cm\ClaimMaster Installation\Release\ClaimMaster Installation.msi"
Dim newVersion : newVersion = ""
Dim console : If UCase(Mid(Wscript.FullName, Len(Wscript.Path) + 2, 1)) = "C" Then console = True
' Connect to Windows Installer object
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
Dim errMsg
' Open database
Dim database, openMode, view, record, updateMode, sumInfo
openMode = msiOpenDatabaseModeTransact
Set database = installer.OpenDatabase(databasePath, openMode) : CheckError
' Create an install session and execute actions in order to perform directory resolution
installer.UILevel = msiUILevelNone
Dim session : Set session = installer.OpenPackage(database,1) : If Err <> 0 Then Fail "Database: " & databasePath & ". Invalid installer
package format"
Dim stat : stat = session.DoAction("CostInitialize") : CheckError
If stat <> 1 Then Fail "CostInitialize failed, returned " & stat
' Get the product version
Dim nametofind : nametofind = "'ProductVersion'"
Dim versionview
Set versionview = database.OpenView("SELECT Value FROM Property WHERE Property = " &nametofind ) : CheckError
versionview.Execute : CheckError
Set record = versionview.Fetch : CheckError
If record Is Nothing Then
message1 = "did not find the product version"
wscript.Echo message1
Else
newVersion = record.StringData(1)
End if
' List all files in the msi package
Set view = database.OpenView("SELECT FileName,FileSize,Attributes,Language,Version,Sequence FROM File " ) : CheckError
view.Execute : CheckError
' Fetch each file and request the source path, then verify the source path, and get the file info if present
Dim fileKey, fileName, folder, sourcePath, fileSize, version, language, delim, message, info
Do
Set record = view.Fetch : CheckError
If record Is Nothing Then Exit Do
' update File table info
If record.StringData(3) = "512" Then
record.StringData(5) = newVersion
End If
view.Modify msiViewModifyUpdate, record : CheckError
Loop
' Commit database in case updates performed
database.Commit : CheckError
Wscript.Quit 0
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 & vbNewLine & errRec.FormatText
End If
Fail message
End Sub
Sub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End Sub
' Windows Installer utility to report or update file versions, sizes, languages
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) Microsoft Corporation. All rights reserved. - changed by pepper
' Demonstrates the access to install engine and actions
'
Option Explicit
' FileSystemObject.CreateTextFile and FileSystemObject.OpenTextFile
Const OpenAsASCII = 0
Const OpenAsUnicode = -1
' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist = 0
' FileSystemObject.OpenTextFile
Const OpenAsDefault = -2
Const CreateIfNotExist = -1
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Const msiViewModifyInsert = 1
Const msiViewModifyUpdate = 2
Const msiViewModifyAssign = 3
Const msiViewModifyReplace = 4
Const msiViewModifyDelete = 6
Const msiUILevelNone = 2
Const msiRunModeSourceShortNames = 9
Const msidbFileAttributesNoncompressed = &h00002000
Dim message1
Dim databasePath : databasePath = "H:\active\claim_master_work\wv2008\cm\ClaimMaster Installation\Release\ClaimMaster Installation.msi"
Dim newVersion : newVersion = ""
Dim console : If UCase(Mid(Wscript.FullName, Len(Wscript.Path) + 2, 1)) = "C" Then console = True
' Connect to Windows Installer object
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
Dim errMsg
' Open database
Dim database, openMode, view, record, updateMode, sumInfo
openMode = msiOpenDatabaseModeTransact
Set database = installer.OpenDatabase(databasePath, openMode) : CheckError
' Create an install session and execute actions in order to perform directory resolution
installer.UILevel = msiUILevelNone
Dim session : Set session = installer.OpenPackage(database,1) : If Err <> 0 Then Fail "Database: " & databasePath & ". Invalid installer
package format"
Dim stat : stat = session.DoAction("CostInitialize") : CheckError
If stat <> 1 Then Fail "CostInitialize failed, returned " & stat
' Get the product version
Dim nametofind : nametofind = "'ProductVersion'"
Dim versionview
Set versionview = database.OpenView("SELECT Value FROM Property WHERE Property = " &nametofind ) : CheckError
versionview.Execute : CheckError
Set record = versionview.Fetch : CheckError
If record Is Nothing Then
message1 = "did not find the product version"
wscript.Echo message1
Else
newVersion = record.StringData(1)
End if
' List all files in the msi package
Set view = database.OpenView("SELECT FileName,FileSize,Attributes,Language,Version,Sequence FROM File " ) : CheckError
view.Execute : CheckError
' Fetch each file and request the source path, then verify the source path, and get the file info if present
Dim fileKey, fileName, folder, sourcePath, fileSize, version, language, delim, message, info
Do
Set record = view.Fetch : CheckError
If record Is Nothing Then Exit Do
' update File table info
If record.StringData(3) = "512" Then
record.StringData(5) = newVersion
End If
view.Modify msiViewModifyUpdate, record : CheckError
Loop
' Commit database in case updates performed
database.Commit : CheckError
Wscript.Quit 0
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 & vbNewLine & errRec.FormatText
End If
Fail message
End Sub
Sub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End Sub
Posted by:
sk
15 years ago
Indeed, companion files/parents is a good option if you have a file with a higher version. It could also be done creating a component with a dummy file (empty text for example) and set that file as keypath for the component. Then add the other files to that component. If you have files that install in different directories you have to repeat this for each directory. A simple custom action that copies the file is also a possibility.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.