Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

VBScript custom action in the progress dialog?

Hello,

Can you run a VBScript custom action when the progress dialog of either the main installation or prerequisite installation dialog is shown? I added the custom action to the Init Events section and did not work.

:?:
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,

First of all, Dialog initialization events (Init Events) allow you to execute actions right before the current dialog is displayed.
Can you run a VBScript custom action when the progress dialog of either the main installation or prerequisite installation dialog is shown?
Yes, this is possible. For example, I have tested this using a VBScript that simply shows a message box before the "ProgressDlg" of my main package. After creating the custom action without sequence, I went to Dialogs page and added on the "ProgressDlg" the Init Event with the following parameters:

-Event: ExecuteCustomAction
-Argument: ExecuteScriptCode
-Condition: Left unchanged (the default condition is "AI_INSTALL")

If this does not help, can you please give me some more details about your scenario so I can further investigate it? For example, what is your VBScript custom action trying to do? Also, if you could attach a sample which we could test on our side, that would be really helpful.

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

Hello,

The custom action is executed during the prerequisite dialog progress dialog before the main installation. The VBScript writes an INI file. This works fine if the custom action is given in the Init Events section in the previous dialog before the prerequisite progress dialog. I tried with conditions AI_BOOTSTRAPPER and AI_INSTALL. It did not work. Here is the VBScript used,

Code: Select all

'on error resume next

WriteIni Session.Property("MY_FILE_PATH"), "Default", "Level", "One"

Function ReadIni( myFilePath, mySection, myKey )
    ' This function returns a value read from an INI file
    '
    ' Arguments:
    ' myFilePath  [string]  the (path and) file name of the INI file
    ' mySection   [string]  the section in the INI file to be searched
    ' myKey       [string]  the key whose value is to be returned
    '
    ' Returns:
    ' the [string] value for the specified key in the specified section
    '
    ' CAVEAT:     Will return a space if key exists but value is blank
    '
    ' Written by Keith Lacelle
    ' Modified by Denis St-Pierre and Rob van der Woude

    Const ForReading   = 1
    Const ForWriting   = 2
    Const ForAppending = 8

    Dim intEqualPos
    Dim objFSO, objIniFile
    Dim strFilePath, strKey, strLeftString, strLine, strSection

    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

    ReadIni     = ""
    strFilePath = Trim( myFilePath )
    strSection  = Trim( mySection )
    strKey      = Trim( myKey )

    If objFSO.FileExists( strFilePath ) Then
        Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
        Do While objIniFile.AtEndOfStream = False
            strLine = Trim( objIniFile.ReadLine )

            ' Check if section is found in the current line
            If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
                strLine = Trim( objIniFile.ReadLine )

                ' Parse lines until the next section is reached
                Do While Left( strLine, 1 ) <> "["
                    ' Find position of equal sign in the line
                    intEqualPos = InStr( 1, strLine, "=", 1 )
                    If intEqualPos > 0 Then
                        strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
                        ' Check if item is found in the current line
                        If LCase( strLeftString ) = LCase( strKey ) Then
                            ReadIni = Trim( Mid( strLine, intEqualPos + 1 ) )
                            ' In case the item exists but value is blank
                            If ReadIni = "" Then
                                ReadIni = " "
                            End If
                            ' Abort loop when item is found
                            Exit Do
                        End If
                    End If

                    ' Abort if the end of the INI file is reached
                    If objIniFile.AtEndOfStream Then Exit Do

                    ' Continue with next line
                    strLine = Trim( objIniFile.ReadLine )
                Loop
            Exit Do
            End If
        Loop
        objIniFile.Close
    Else
        WScript.Echo strFilePath & " doesn't exists. Exiting..."
        Wscript.Quit 1
    End If
End Function

Sub WriteIni( myFilePath, mySection, myKey, myValue )
    ' This subroutine writes a value to an INI file
    '
    ' Arguments:
    ' myFilePath  [string]  the (path and) file name of the INI file
    ' mySection   [string]  the section in the INI file to be searched
    ' myKey       [string]  the key whose value is to be written
    ' myValue     [string]  the value to be written (myKey will be
    '                       deleted if myValue is <DELETE_THIS_VALUE>)
    '
    ' Returns:
    ' N/A
    '
    ' CAVEAT:     WriteIni function needs ReadIni function to run
    '
    ' Written by Keith Lacelle
    ' Modified by Denis St-Pierre, Johan Pol and Rob van der Woude

    Const ForReading   = 1
    Const ForWriting   = 2
    Const ForAppending = 8

    Dim blnInSection, blnKeyExists, blnSectionExists, blnWritten
    Dim intEqualPos
    Dim objFSO, objNewIni, objOrgIni, wshShell
    Dim strFilePath, strFolderPath, strKey, strLeftString
    Dim strLine, strSection, strTempDir, strTempFile, strValue

    strFilePath = Trim( myFilePath )
    strSection  = Trim( mySection )
    strKey      = Trim( myKey )
    strValue    = Trim( myValue )

    Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
    Set wshShell = CreateObject( "WScript.Shell" )

    strTempDir  = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
    strTempFile = objFSO.BuildPath( strTempDir, objFSO.GetTempName )

    Set objOrgIni = objFSO.OpenTextFile( strFilePath, ForReading, True )
    Set objNewIni = objFSO.CreateTextFile( strTempFile, False, False )

    blnInSection     = False
    blnSectionExists = False
    ' Check if the specified key already exists
    blnKeyExists     = ( ReadIni( strFilePath, strSection, strKey ) <> "" )
    blnWritten       = False

    ' Check if path to INI file exists, quit if not
    strFolderPath = Mid( strFilePath, 1, InStrRev( strFilePath, "\" ) )
    If Not objFSO.FolderExists ( strFolderPath ) Then
        WScript.Echo "Error: WriteIni failed, folder path (" _
                   & strFolderPath & ") to ini file " _
                   & strFilePath & " not found!"
        Set objOrgIni = Nothing
        Set objNewIni = Nothing
        Set objFSO    = Nothing
        WScript.Quit 1
    End If

    While objOrgIni.AtEndOfStream = False
        strLine = Trim( objOrgIni.ReadLine )
        If blnWritten = False Then
            If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
                blnSectionExists = True
                blnInSection = True
            ElseIf InStr( strLine, "[" ) = 1 Then
                blnInSection = False
            End If
        End If

        If blnInSection Then
            If blnKeyExists Then
                intEqualPos = InStr( 1, strLine, "=", vbTextCompare )
                If intEqualPos > 0 Then
                    strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
                    If LCase( strLeftString ) = LCase( strKey ) Then
                        ' Only write the key if the value isn't empty
                        ' Modification by Johan Pol
                        If strValue <> "<DELETE_THIS_VALUE>" Then
                            objNewIni.WriteLine strKey & "=" & strValue
                        End If
                        blnWritten   = True
                        blnInSection = False
                    End If
                End If
                If Not blnWritten Then
                    objNewIni.WriteLine strLine
                End If
            Else
                objNewIni.WriteLine strLine
                    ' Only write the key if the value isn't empty
                    ' Modification by Johan Pol
                    If strValue <> "<DELETE_THIS_VALUE>" Then
                        objNewIni.WriteLine strKey & "=" & strValue
                    End If
                blnWritten   = True
                blnInSection = False
            End If
        Else
            objNewIni.WriteLine strLine
        End If
    Wend

    If blnSectionExists = False Then ' section doesn't exist
        objNewIni.WriteLine
        objNewIni.WriteLine "[" & strSection & "]"
            ' Only write the key if the value isn't empty
            ' Modification by Johan Pol
            If strValue <> "<DELETE_THIS_VALUE>" Then
                objNewIni.WriteLine strKey & "=" & strValue
            End If
    End If

    objOrgIni.Close
    objNewIni.Close

    ' Delete old INI file
    objFSO.DeleteFile strFilePath, True
    ' Rename new INI file
    objFSO.MoveFile strTempFile, strFilePath

    Set objOrgIni = Nothing
    Set objNewIni = Nothing
    Set objFSO    = Nothing
    Set wshShell  = Nothing
End Sub
K
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

Indeed, I was able to reproduce this behavior. It seems like this is an issue of Advanced Installer in what regards the support for Init Events for the Pre-Install prerequisites dialog.

A fix will be available in a future version of Advanced Installer, thank you for bringing this to our attention.

We will update this thread as soon as a fix will be available.
I understand. Thank you for your help.

:)
Last edited by Codename K on Tue Jul 31, 2018 1:32 pm, edited 2 times in total.
K
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

Indeed, I was able to reproduce this behavior. It seems like this is an issue of Advanced Installer in what regards the support for Init Events for the Pre-Install prerequisites dialog.

A fix will be available in a future version of Advanced Installer, thank you for bringing this to our attention.

We will update this thread as soon as a fix will be available.
I understand. Thank you for your help.

:)
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,

Indeed, I was able to reproduce this behavior. It seems like this is an issue of Advanced Installer in what regards the support for Init Events for the Pre-Install prerequisites dialog.

A fix will be available in a future version of Advanced Installer, thank you for bringing this to our attention.

We will update this thread as soon as a fix will be available.

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

You're always welcome!

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

Hello again,

I need to run the VBScript custom action during the prerequisites progress dialog becasue it needs to be only executed if any prerequisites software is selected to be installed. If no prerequisites is selected then it will not show the prerequisites progress dialog and does not run the VBScript custom action. The VBScript custom action seems to be working fine when the Next button is clicked from the prerequisites selection dialog.

I am planning to set the VBScript custom action to run when the Next button is clicked from the prerequisites selection dialog.

What is the condition that needs to be given to not run the VBScript custom action if no prerequisite is selected?
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,

After talking with the development team, it seems that, unfortunately, what you want to achieve is not possible. This happens because the "ProgressPrereqDlg" is always displayed, even if no prerequisites are selected from the previous dialog ("PrerequisiteDlg").

As a workaround, you can add you prerequisite as a "Feature-Based" prerequisite. This way, a new feature will be created for each of your prerequisites, thus you will be able to condition the execution of your VBSript Custom Action based on the state of the feature that contains the prerequisite, if it was / was not selected for install.

To do so, you can go to Dialogs page and add an "OptionalFeatsDlg" after the "WelcomeDlg". After that, you can click on the next dialog and under "Init Events" click on the "New..." button and create an event with the following parameters:

-Event: Execute custom action
-Argument: ExecuteScriptCode
-and the Condition field should look something similar to this:

Code: Select all

AI_INSTALL AND ( ( (&PrereqFeature = 3) AND NOT (!PrereqFeature = 3) ) )
where "PrereqFeature" represents the name of your prerequisite assigned feature.

Also, the "OptionalFeatsDlg" contains all the features that are in your project, so please keep in mind that you should not include the features that are not related to your prerequisites in the condition which is used to decide the execution of your custom action.

Hope this helps!

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

As a workaround, you can add you prerequisite as a "Feature-Based" prerequisite. This way, a new feature will be created for each of your prerequisites, thus you will be able to condition the execution of your VBSript Custom Action based on the state of the feature that contains the prerequisite, if it was / was not selected for install.
Will this work for ".NET Framework 4.5" and "SQL Server Express"?
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,
Will this work for ".NET Framework 4.5" and "SQL Server Express"?
I would not recommend you to put .NET Framework 4.5 and SQL Server Express as feature based prerequisites.

However, here is another workaround you can try for your problem:

-Still keep the .NET Framework and SQL Server Express as Pre-Install prerequisites.
-Create a dummy project (.aip) which will only be used to execute your VBScript custom action. In order to do this, you can add your VBScript as a temporary file and then use a LaunchFile custom action.
-In the same dummy project, go to "Product Details" page and under "Add or Remove Programs (Control Panel)", uncheck the "Register product with Windows Installer" option. This way, it will not appear in Control Panel as an application.
-After building the dummy project, add it as a "Pre-Install" prerequisite.
-Click on it and under "Install Conditions" tab --> check the "Install prerequisite based on conditions" option --> check the "Install only if this prerequisite is being installed:" option and choose the prerequisite you want to condition the execution of the script on.

This way, if your chosen prerequisite will be installed, your dummy setup will also be deployed, executing your VBScript.

Hope this helps!

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

After building the dummy project, add it as a "Pre-Install" prerequisite.
The dummy installer shows under the main prerequisite in the dialog. Is there a way to hide it?
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,

Unfortunately, we do not have support to hide a certain prerequisite from "PrerequisitesDlg" dialog.

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codename K
Posts: 471
Joined: Fri Jan 29, 2010 3:04 pm

Re: VBScript custom action in the progress dialog?

OK. I understand. Thanks for your help so far.
Unfortunately, we do not have support to hide a certain prerequisite from "PrerequisitesDlg" dialog.
Will this function be added in the future?

:)
K
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: VBScript custom action in the progress dialog?

Hello,

You're always welcome.

I have forwarded this to the development team. Unfortunately, it has a low priority due to the fact that you are the first one to ask for this.

If more users will ask for this, we will increase its priority and we will let you know when this will be added.

Unfortunately, until then, I can not give you any estimation on when this will be implemented.

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”