cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
arnoldmoreno
Level 3

Insert Record to IniFile

Howdy,

Would appreciate a nudge in the right direction here:

Using InstallShield 2008 Pro and have a legacy install that writes an INI file with a reference to the CD Rom drive letter and folder. I need to install this software where the possibility of the CD Rom having a different drive letter is possible.

Searched and found the vbs code to find the drive letter:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

dim myVariableName

For Each objItem in colItems
myVariableName = objItem.Drive & "\grade4\"
Next


I've added the "\grade4\" because that's a folder on the CD that has the data the program uses.

I've looked into inserting a record into the IniFile table and have come up with the following:

Dim MsiDb
Dim MsiInstall
Dim MsiRecord
Dim MsiView

Set MsiDb = Session.Database
Set MsiInstall = Session.Installer
Set MsiView = MsiDb.OpenView("SELECT * FROM IniFile")
Set MsiRecord = MsiInstall.CreateRecord(8)
MsiRecord.StringData(2) = "WELCOME.INI"
MsiRecord.StringData(3) = "INSTALLDIR"
MsiRecord.StringData(4) = "Environment"
MsiRecord.StringData(5) = "DefaultPath"
MsiRecord.StringData(6) = myVariableName"
MsiRecord.StringData(7) = "1
MsiRecord.StringData(8) = "IniFileEntries"
Call MsiView.Execute(MsiRecord)
Call MsiView.Modify (4, MsiRecord)
Call MsiView.Close


Checking the install log after an attempted install, I get an error for my Custom Action pointing to Call MsiView.Modify (7, MsiRecord). I've read a little where the number depends on the type of table being used. A table with a key file can only be modified a certain way. As seen above, I don't populate MsiRecord.StringData(1) because when you insert a record by hand, IniFile table, the IniFile column (key) is autoinserted.

I've tried the CA in different modes (immediate, deferred, commit) as well with no success.

Any help would be greatly appreciated!

Thanks,
Arnold Moreno
NISD - NEDSS
Labels (1)
0 Kudos
(2) Replies
RobertDickau
Flexera Alumni

Instead of modifying the in-memory IniFile table, perhaps create a normal INI entry but use a property ([CD_DRIVE_LETTER]) as the INI data; and then use a custom action to set the property value? With InstallScript, for example, there's a GetValidDrivesList function that can help.
0 Kudos
arnoldmoreno
Level 3

Thanks for your help, Robert!

Used Installscript's GetValidDrivesList and did a little extra reading up to properly use MsiSetProperty and voila! Success!!

Appreciate your help.

- Arnold
0 Kudos