Oliver Paals
Posts: 7
Joined: Fri Apr 24, 2020 10:05 am
Location: Germany

Replace configuration file using 'Custom Actions'

Hello,

I would like to replace a configuration file using a custom action of type 'Execute Inline Script Code'
I chose script type 'Visual basic script(*.vbs)'
Install execution stage is the last custom action in 'Add Resources' stage.

The problem is, that the configuration file is not changed after the setup has finished.

Running the vbs-script manually after the installation works, but not from AI-Setup.

Here is my vbs-script:

Code: Select all

  On Error Resume Next
  Const appDataDir = "C:\ProgramData\MyCompany\ApplicationData\PostgreSQL\10\data"
  Const configFileName = "postgresql.conf"

  Dim fso

  'Konfigurationsdatei austauschen:
  Set fso = CreateObject("Scripting.FileSystemObject")

  call fso.CopyFile(".\"  & configFileName, appDataDir & "\" & configFileName, True)

  Set fso = Nothing
I used the following settings in 'Execute Inline Script Code' dialog:
Properties:
+ 32-bit script
+ No action data
+ Script type: Visual basic script(*.vbs)
Execution Time:
+ After the system has been successfully modified (commit)
Execution options:
+ Run under the LocalSystem account with full privileges (no impersonation)
+ Wait for custom action to finish before proceeding
+ Fail installation if cutom action returns an error
Execution Stage Condition:
+ Install
+ Maintenance
+ No condition

Thanks in advance
Oliver
LittleCoder
Posts: 1
Joined: Wed May 27, 2020 11:35 am

Re: Replace configuration file using 'Custom Actions'

Maybe you can try to execute the script through a "Run script from file" instead of "Run inline script" custom action.
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: Replace configuration file using 'Custom Actions'

Hello Oliver,

At a first glance, the custom action seems correctly configured.

Few things that come to my mind are:

1. make sure that the provided path to the config file is correct. From what I can see, you give a hard coded path to the config file. When running the script after installing the setup, you use the exact same path? If so, then this point can be ignored.

2. from what I can see, the config file is not from your main package, it is a config file for a prerequisite of yours - PostgreSql. There might be the case when the file is not present on the machine when the custom action runs. For instance, if:
  • the prerequisite is of post-install type, then the custom action might execute before the installation of the prerequisite, meaning that the config file is not present on the machine when the custom action executes
  • the prerequisite is of feature-based type and the main setup runs silently. In this case, the prerequisite will be installed as a post-install prerequisite (see the case above)
Could you please let me know if you are in any of the scenarios above?
Maybe you can try to execute the script through a "Run script from file" instead of "Run inline script" custom action.
Hello and welcome to our forums. Unfortunately, I'm afraid that the custom action "type" (either from file or inline) is not related to Oliver's problem here. Please see my above answer for more information.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Oliver Paals
Posts: 7
Joined: Fri Apr 24, 2020 10:05 am
Location: Germany

Re: Replace configuration file using 'Custom Actions'

Hello Catalin,
thanks for your reply.

I think the scenario "the prerequisite is of feature-based type and the main setup runs silently. In this case, the prerequisite will be installed as a post-install prerequisite (see the case above)" is my scenario. The main installation is running silently and PostgresDB is installed as a prerequsite.

What I don't understand is, at which time the custom action is executed. Is there a difference between silent and not silent installation?

Best regards,
Oliver
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: Replace configuration file using 'Custom Actions'

Hello Oliver,
I think the scenario "the prerequisite is of feature-based type and the main setup runs silently. In this case, the prerequisite will be installed as a post-install prerequisite (see the case above)" is my scenario. The main installation is running silently and PostgresDB is installed as a prerequsite.
Alright, good to know this.
What I don't understand is, at which time the custom action is executed. Is there a difference between silent and not silent installation?
No, there isn't any difference between when the custom action is executed during a silent / full UI installation.

The problem here is the prerequisite sequencing. A feature-based prerequisite is installed right before the main installation, when you press the "Install" button in the UI. If the main package is installed silently, the UI is not spawned, therefore there isn't any "Install" button. This has forced us to move the sequencing of feature-based prerequisite when the main package is installed silently to the post-install stage.

In what regards the sequencing of your custom action, it executes at the same time it should. However, the prerequisite is installed after the custom action is executed ==> when the custom action executes, there is no config file on the machine (since the prerequisite has not yet been installed).

Unfortunately, this being the case, we can not execute the custom action after the installation of the prerequisite, because the prerequisite is run asynchronously at the end of the installation.

However, what we can do is the following:

- create a boostrapper msi package that will only contain your custom action

- add your custom action in this boostrapper package

- add the resulted MSI as a prerequisite, scheduled after the PostgreSQL prerequisite

As the prerequisites are installed in the order specified in the "Prerequisites" page, the PostgreSQL will be run and then the package that contains the custom action will run, modifying your config file.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Oliver Paals
Posts: 7
Joined: Fri Apr 24, 2020 10:05 am
Location: Germany

Re: Replace configuration file using 'Custom Actions'

Hello Catalin,

sorry for my late answer, but I took my some time to try out your solution (and I had several other things to do).

Finally it works properly. The key was indeed the prerequisite sequencing, which runs now as expected since I use a separate MSI-Installer for the configuration of the Postgres database.

Thank you very much for your help!

Best regards,
Oliver
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: Replace configuration file using 'Custom Actions'

Hello Oliver,

You are always welcome!

I am glad to hear everything works as expected now.

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

Return to “Building Installers”