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.
yES THANK YOU
Great script! Exactly what I was looking for.
The only problem is the download doesn’t work.
A error 404 occures with the following text:
Fatal error: Cannot use object of type WP_Error as array in D:xampphtdocsblogwp-contentthemescoretechsidebar.php on line 52
Hello Elwin!
Thank you.
I am sorry that you could not download.
We have recently updated our blog system.
The error is fixed now, and the download should work.
Thank you notifying us about the error.
Have a nice day
Thanks!
The download is working now.
I’m quite new to VB2008 and I don’t understand how to make the script working.
I have made a office addin and created a Deployment Project.
The script is added to the Deployment Project.
I don’t understand the Usage part of your description.
Where do I find “InstallInitialize” and “ResolveSource”?
Thanks in advance.
Hello Elwin,
I am sorry for the late reply.
I dont think you can edit the script part of the MSI Package in visual studio!
That is why i had to edit it in Wise Package Studio.
You might be able to put the script into Custom Actions in Visual Studio, but i am not sure how.
I always use Wise Package Studio for creating and editing packages, it has many more functions than Visual Studio.
The only time i use VS for MSI packages, is when i am creating an installer for my own projects.
– Jakob
Hi,I want to study vbscript for using QTP, but i have not enough resoruce that help a beginner to study it. so can you recommend some information to me.
Thanks.
in my country, the resource about vbscript is very exility.
help me pls.
send some information to my email.
[…] upon the need to determine the dimensions of some images. Because the script was being written inAutomated Windows Installer Properties from .INI (Embedded …Download: Have you ever needed the functionality to read the property values from an .ini file, […]
um this is nice but why re architect something that already is working fine out of the box.
appSearch has this capability already.
Hello john
Welcome to my blog.
As far as i know and have read in forums like this http://community.installshield.com/archive/index.php?t-93220.html
appSearch only supports looking for ini files in the windows directory, that was not what i needed in this case.
Do you have a way of making appsearch/inilocator search in the same folder as the MSI file, without using script? 🙂
– Jakob
Very nice article. I definitely love this website.
Stick with it!