sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Reading value from INI during Install

I'm trying to convert from an InstallShield InstallScript project to AdvancedInstaller. The basics seem pretty easy, but now I'm getting into pre-req tests, and more customization to validate that the install is actually reasonable.

I need to be able to read an INI file that is produced during the build of our app. We use the information in the INI to confirm at install time that the application being installed is compatible with the database that it is being installed against.

If I add (Import) the file, I can (via a UI editor) make changes to the file, but I cant see a way to access the file as a set of properties (I'm assuming this is the best way to attack this, as decisions would be needed within the dialog flow to allow/disallow the installer to continue).
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Reading value from INI during Install

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

In order to achieve what you want you can take a look on our "Read path from text file and copy file there" thread which may be helpful for you.

Let us know if this helps, otherwise please give us more details about your scenario.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

More Details:

Currently usign Advanced Installer 9.7 Enterprise in Trial mode as we evaluate if this product can meet our requirements.

I need to return a string value back from the INI file. This represents the Database compatability version (which I'll later use in a query against the database to determine if the application will be allowed to be installed).

I have added a custom action I called 'ReadINI' and added it's execution it to the PrepareDlg. This seemed to be the best place as I had planned on displaying the DB compatability requirement on the WelcomeDlg, and I thought putting it early in the process would ensure that it was made available before anything else was instantiated. However, there is a small dialog pop up that shows a warning symbol and the error "Selection Manager not initialized"... so perhaps this is misplaced.

The actual process however, is still a problem. As the VBScript custom actions can only return numeric responses, and based on another article, I'm returning the result by setting the "session.property" . as such:

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("InstallInfo.ini",1)
set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )

Do Until objFile.AtEndOfStream
	strNextLine = trim(objFile.Readline)
	if ( instr(strNextLine,"=") > 0 ) then
		SplitArg=split(strNextLine,"=")

		if SplitArg(0) = "CompatibleDBVersion" then
			call CreateEnvVar("INSTALLER_DBVersion" , SplitArg(1) )
		end if
	end if
loop
set wshSystemEnv = nothing
set wshShell = nothing
set objFile = nothing
set objFSO = nothing


sub CreateEnvVar(strVarName,strVarValue)
'	if (Ucase(Right((wscript.FullName),11)) <> "CSCRIPT.EXE") then
		Session.Property(strVarName) = strVarValue
'	else
'		wscript.echo "Would set " & strVarName & " to " & strVarValue
'	end if
end sub
(I've structured it like this so that I can return other information from the INI at a later time)

And in order for the result to be picked up, I've created a property

Name: [INSTALLER_DBVersion]
Value :initval

When I attempt to show the property I've created (next dialog), the value that shows as 'initval'. Either the script isnt being triggered (perhaps this is what the error dialog is telling me?) or the Sesson.Property isnt resetting the value in the runtime.

When I run the script myself (with the comments removed), I see the expected output - so I know its parsing the INI properly... but the session.property doesnt work interactively, so I cant test that part.

There's probably something very simple I've overlooked. Appreciate your help.
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

Additional:

The MSI log shows the "readIni" is being called

Code: Select all

MSI (c) (94!10) [12:02:27:785]: Doing action: readini
Action 12:02:27: readini. 
Action start 12:02:27: readini.
MSI (c) (94!10) [12:02:27:785]: Note: 1: 2731 2: 0 
Error 2731. Selection Manager not initialized.
MSI (c) (94!10) [12:04:52:514]: Product: TestInstaller -- Error 2731. Selection Manager not initialized.

Action ended 12:04:52: readini. Return value 3.
Action ended 12:04:52: AI_Init_PrepareDlg. Return value 1.
And this is where the Error popup is coming from...
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

Ok - I have moved the script to the next dialog (WelcomDlg) and I see a different error that points to a failing in my concept.

The script hasnt been copied to the Target computer - so it's unable to be executed. (makes perfect sense now).

So how do I include a script file to be executed before the files are actually copied to the target computer?

When I add the script as an attached file, the source path is referenced with a hard coded path to the actual script on the build machine, which is not able to be edited, and the installer complains that it cant find it with the path (from the build machine) at run time.

I cant add the script as an installed file, as it's not been copied yet.

This is a VBScript - not a DLL so the other options dont make sense...
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

OK - banging my head against this all day now, and I have made some headway - but now have hit a brick wall.

I've added the script, and the INI file I need to read, as Temporary files. These seem to get deployed early in the sequence... so now my script is executing (its sequenced in the wizard between "Searches" and "Paths resolution".

However - I cant find the INI files - I'm guessing it gets named as a temporary name when it gets copied to the %TEMP% directory....

Is there any way to refer back to the installation set? the INI will have a known name there...

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject( "WScript.Shell" )
INIFile = wshShell.ExpandEnvironmentStrings( "%temp%\BMSSteps.ini" )  
Set objFile = objFSO.OpenTextFile(INIFile,1)

Do Until objFile.AtEndOfStream
   strNextLine = trim(objFile.Readline)
   if ( instr(strNextLine,"=") > 0 ) then
      SplitArg=split(strNextLine,"=")

      if SplitArg(0) = "CompatibleDBVersion" then
         call CreateEnvVar("INSTALLER_DBVersion" , SplitArg(1) )
      end if
   end if
loop

set wshShell = nothing
set objFile = nothing
set objFSO = nothing

wscript.quit 1

sub CreateEnvVar(strVarName,strVarValue)

      Session.Property(strVarName) = strVarValue

end sub
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

Ok - I have finally hacked this to the point that the log shows the Property being updated.

And I'm not sure why I had to do this, but I ended up passing [SOURCEDIR]TempFolder\InstallInfo.ini as the file reference to the INI file.

I would have thought there would be a mechanism for accessing the files that are part of the install set easier than this... (but this works - it just isnt obvious)

Code: Select all

MSI (c) (8C:D8) [16:41:19:719]: Doing action: readini.vbs
Action 16:41:19: readini.vbs. 
Action start 16:41:19: readini.vbs.
MSI (c) (8C!D8) [16:41:21:497]: PROPERTY CHANGE: Adding INSTALLER_DBVersion property. Its value is '5.4.4.33'.
Action ended 16:41:22: readini.vbs. Return value 0.
MSI (c) (8C:D8) [16:41:22:231]: Doing action: WelcomeDlg
Action 16:41:22: WelcomeDlg. 
However the screen does not show the updated property. It still shows the default value ( "-temp-") I entered when II defined the property on the Install Parameters pane.

Is this a sequence issue? The script runs before the Dialog that shows this... but perhaps it's running before the property is being initialized.

Suggestions?? I would like the property resolved by the script before the WelcomeDlg is shown...
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Reading value from INI during Install

Hello,
And I'm not sure why I had to do this, but I ended up passing [SOURCEDIR]TempFolder\InstallInfo.ini as the file reference to the INI file.

I would have thought there would be a mechanism for accessing the files that are part of the install set easier than this... (but this works - it just isnt obvious)
In order to reference the related ini file through your VB Script file you can use its associated property. Go to "Files and Folders" page, select the ini file and from its context menu choose "Properties..." option. You can use the associated property from "Edit Temporary File" dialog.
Is this a sequence issue? The script runs before the Dialog that shows this... but perhaps it's running before the property is being initialized.
If your script file is added as temporary file to your project, then you should schedule your VB Script custom action after "Wizard Dialogs Stage -> Paths Resolution -> CostFinalize" standard action.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sbrown_el
Posts: 20
Joined: Wed Dec 05, 2012 4:07 pm

Re: Reading value from INI during Install

Daniel.Radu wrote:Hello,

Let us know if this helped.

All the best,
Daniel
Yes, thanks
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Reading value from INI during Install

You're welcome. Glad to help.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”