jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

I need to run a custom action BEFORE starting a Windows Service

Hello,

I developed an application that has a Windows Service.

The installer has a custom action that modifies the configuration file of the service in order to set the correct database connection string.

The problem is that the service tries to be started before the custom action, so it obviously crashes because there is no connection string configured.

At what stage can I run my custom action to ensure it is run before the service is going to be started?

Currently I have placed it after "Finish Execution" stage.

Regards
Jaime
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: I need to run a custom action BEFORE starting a Windows Service

Hello Jaime,

A service is installed during the "Add Resources" action group --> "InstallServices" standard action.

In order to schedule your custom action before the "InstallServices" custom action, you can proceed as it follows:

1. go to "Custom Actions" page.

2. under "Install Execution Stage" --> right click on "Add resources" action group --> "Show Standard Action" --> "Add Resources" --> click on "InstallServices"

After that, simply schedule your custom action by drag & dropping it to the appropriate point.

If you need to run it before starting the service, you can proceed the same as above, but simply replace the "InstallServices" standard action with "StartServices" action.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

Re: I need to run a custom action BEFORE starting a Windows Service

Hello,

sorry but that did not work.

After some attempts, I am attaching final configuration.

The script is always run before copiyng the files.

Regards
Jaime
Attachments
Sequence.png
Sequence.png (11.97 KiB) Viewed 7044 times
jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

Re: I need to run a custom action BEFORE starting a Windows Service

Something is coming to my attention.

As other attempt, I added my custom script after Start Service stage.

I see in the wizard window the status "Starting Services", and then my message box is shown (see the picture).

Then, all files started being copied. And after that, I see the status "Starting Services" again and my message box did not appeared again. What is going on?

Regards
Jaime
Attachments
starting services.png
starting services.png (70.53 KiB) Viewed 7044 times
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: I need to run a custom action BEFORE starting a Windows Service

Hello Jaime,

I forgot to mention this in my last thread, but the "InstallService" standard action takes place during the deferred stage.

With that being said, your custom action must have its execution time set to "When the system is being modified (deferred)".

Hope this helps.

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

Re: I need to run a custom action BEFORE starting a Windows Service

You are always welcome, Jaime!

I'm glad you got this working.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

Re: I need to run a custom action BEFORE starting a Windows Service

Hello Catalin,

something happened that this does not work anymore.

I am attaching the AIP file.... I have checked and re-checked that the configuration of custom action is correct, however, it is not executed before installing the service.

Regards
Jaime
Attachments
Control de Visitas 3.aip
(93.25 KiB) Downloaded 208 times
jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

Re: I need to run a custom action BEFORE starting a Windows Service

Hello,

it turned out that the VBS file had a syntax error.

Unfortunately, Advanced Installer log does not log that, even when I checked the "Enable verbose logging" option. I think this kind of errors should be logged to make error causes easier to find.

Regards
Jaime
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: I need to run a custom action BEFORE starting a Windows Service

Hello Jaime,

Thank you for your followup on this.

I am glad you found the culprit and that everything works as expected now.

In what regards the logging, unfortunately, since every script is custom made, Advanced Installer cannot log it (since every script can be created differently - for instance, a script can return some value in a failure scenario, whereas another script can return another value, all being up to the user that creates it).

However, if you need to write some events to your VBScript file (that can help when debugging), you can follow the approach described in the "How to write a specific event in the log" article.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jstuardo
Posts: 87
Joined: Mon Nov 09, 2015 10:44 pm

Re: I need to run a custom action BEFORE starting a Windows Service

Dear Catalin,

Of course Advanced Installer cannot log what is inside the VBS execution, but it seems I wasn't very clear.

The problem was a syntax error in the VBS file not allowing the script to run. That error could be logged, actually.

I realized about this when trying to execute the VBS script from outside Advanced Installer by using cscript utility. As you may know, a VBS script is compiled just before it is run, so, when using cscript utility, the syntax error was shown immediately before the actual execution.

Advanced Installer should do the same. It is launching the VBS script somehow by using some utility. That utility should throw any syntax error present in the script but the problem is that this does not happen.

Regards
Jaime
Catalin
Posts: 6582
Joined: Wed Jun 13, 2018 7:49 am

Re: I need to run a custom action BEFORE starting a Windows Service

Hello Jaime,

Thank you for the explanation on this.

I have added your request on our TODO list of improvements and hopefully this will be added in a future version of Advanced Installer. Thank you for bringing this to our attention.

I will update this thread as soon as the improvement will be implemented.

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

Return to “Building Installers”