Download: [download#2#size#nohits]
Have you ever needed the functionality to read the property values from an .ini file, every time a installation or repair is run?
This small script created for Windows installer, will do the job.
Purpose:
Automatically reads a ini file located in the MSI SOURCEDIR property.
Each parameter in the ini file is read into the property that
have the same name.
ex. “DaysSerial”=”0100000” line is read in to property named
DaysSerial and setting the value to 0100000
System works both with “DaysSerial”=”0100000” ini format, or DaysSerial=0100000 ini format.
If you later change the ini file at the source, and do a repair of the msi on the client, the new settings will be used.
NB! I also tried to make a script that could use custom named ini file, based on the commandline parameters, but it is, as far as i know, not possible. If you have an idea of how to do it, please do not hesistate to comments this article.
The problem is that if you later do a repair on the package, it will use the default settings, instead of the custom named ini file. This is why i “hardcoded” the ini filename into the package.
Usage:
Put into MSI package execute deferred after “InstallInitialize” and
“ResolveSource” actions. In this example i have used VBScript Embedded.
NB! You might have to insert the “ResolveSource” action, since it is not allways default.
Script:
' //***************************************************************************
' // ***** Script Header *****
' //
' // Solution: Windows Installer MSI
' // File: ReadINItoMSI.vbs
' // Author: Jakob Gottlieb Svendsen, Coretech A/S. https://blog.ctglobalservices.com
' // Purpose: Automaticly reads a ini file located in the MSI sourcedir.
' // Each parameter in the ini file is read into the property that
' // have the same name.
' // ex. "DaysSerial"="0100000" line is read in to property named
' // DaysSerial settings the value to 0100000
' // System works both with "DaysSerial"="0100000" ini format, or
' // DaysSerial=0100000 ini format
' //
' // Usage: Put into MSI package execute deferred after InstallInitialize and
' // ResolveSource actions
' // Read https://blog.ctglobalservices.com for more instructions and images
' //
' // Warning: This script was tested in a msi package created by Visual Studio 2008
' // and edited in Wise Package Studio.
' // Coretech A/S is not responsible for any damages the script could cause.
' //
' //
' // CORETECH A/S History:
' // 1.0.0 JGS 08/10/2008 Created initial version.
' //
' // Customer History:
' //
' // ***** End Header *****
' //***************************************************************************
'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------
On Error Resume Next
Const ForReading = 1
Const ININame = "Property.ini" ' Name of the .ini file
Dim strFile
'//----------------------------------------------------------------------------
'// Main routines
'//----------------------------------------------------------------------------
strFile = Session.Property("SourceDir") & ININame 'Read the sourcedir parameter from windows installer, and put the filename in the end.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFile, ForReading)
If objFSO.FileExists(strFile) Then
Do While objTextFile.AtEndOfStream <> True
strLine = objtextFile.ReadLine
If inStr(strLine, "=") Then
strLocation = InStr(strLine,"=")
strName = Left(strLine,strLocation - 1)
strValue = Mid(strLine,strLocation + 1,Len(strLine))
strName = Replace(strName,"""","")
strName = Replace(strName,"-","")
strValue = Replace(strValue,"""","")
Session.Property(strName) = strValue
'WScript.Echo strName & " - " & StrValue 'Output Property Names and Value for testing
End If
Loop
End If
'//----------------------------------------------------------------------------
'// End Script
'//----------------------------------------------------------------------------
Warning:
This script was tested in a msi package created by Visual Studio 2008
and edited in Wise Package Studio.
Coretech A/S is not responsible for any damages the script could cause.