Micheal
Posts: 7
Joined: Fri Mar 10, 2006 12:29 pm

Installing file on Target machine based on condition.

Hi,

Can this be achieved? I want to install the some files based on ini value. I have vbscript it will get the value. Here is the VBSCRIPT


'********To read ini File*****
File = "c:\input.ini"
Section = "COMPASS_INSTALL_MODE"
Item = "SILENT"
TEST = ReadIni(FILE,SECTION,ITEM)
msgbox TEST

Function ReadIni( file, section, item )
ReadIni = ""
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
If FileSysObj.FileExists( file ) Then
Set ini = FileSysObj.OpenTextFile( file, 1, False)

Do While ini.AtEndOfStream = False
line = ini.ReadLine

If line = "[" & section & "]" Then
line = ini.ReadLine
Do While Left( line, 1) <> "["
If InStr( line, item & "=" ) = 1 Then
ReadIni = mid( line, Len( item ) + 2 )
Exit Do
End If

If ini.AtEndOfStream Then Exit Do
line = ini.ReadLine
Loop
Exit Do
End If
Loop
ini.Close
End If
End Function


In this script if the TEST value is Y then the files has to be installed other than Y should not install files. How can this be achieved?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi Micheal,

You can achieved this very easy with Advanced Installer. Here how can be done:

1. Create a Property (for ex: TEST) under the "Install Parameters" page with a default value of "Y" on "N".
2. Switch to "Custom Actions" page and add "New Attached Custom Actions" under the "CostInitialize" standard action. If "CostInitialize" standard action is not visible you can make it visible by right clicking on "InstallExecuteSequence" and choosing "Show Standard Action->Before Initialization->CostInitialize".
Use following options for the custom action:
  • 2.1 Function Name: "main" (without quotation marks).
    2.2 Execution Condition: "Not Installed" (without quotation marks).
    2.3 Let all other options to the default value.
3. Switch to "Organization" page and for all components that you want to install based on a condition choose a condition like this: TEST = "Y" (with quotation marks).

I modified your script a little to fit your needs:

Code: Select all

'********To read ini File*****
Function main()
File = "c:\input.ini"
Section = "COMPASS_INSTALL_MODE"
Item = "SILENT"
Session.Property("TEST") = ReadIni(File,Section ,Item)
msgbox Session.Property("TEST") 'for debug only
End Function

Function ReadIni( file, section, item )
ReadIni = ""
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
If FileSysObj.FileExists( file ) Then
Set ini = FileSysObj.OpenTextFile( file, 1, False)

Do While ini.AtEndOfStream = False
line = ini.ReadLine

If line = "[" & section & "]" Then
line = ini.ReadLine
Do While Left( line, 1) <> "["
If InStr( line, item & "=" ) = 1 Then
ReadIni = mid( line, Len( item ) + 2 )
Exit Do
End If

If ini.AtEndOfStream Then Exit Do
line = ini.ReadLine
Loop
Exit Do
End If
Loop
ini.Close
End If
End Function
Please let me know if you encounter any other problems.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
Micheal
Posts: 7
Joined: Fri Mar 10, 2006 12:29 pm

Hi,

That worked and thanks a lot, solved my problem.

Thanks,
Micheal

Return to “Common Problems”