Detect Service (AI custom action) doesn't always work - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Detect Service (AI custom action) doesn't always work

Using AI 7.7:
I've come to like your custom action: DetectService (http://www.advancedinstaller.com/user-g ... rvice.html).
However, to my amazement, I found that this custom action doesn't always work! By saying it doesn't work I mean: when I run it in the LaunchConditions: it works, and it really modifies AI_SERVICE_STATE: I verified this by a messagebox + also seen in the msi log.
However, when I tried to use this custom action under "Uninstall", looking at the log I see that the custom action is called, but neither the logs say that AI_SERVICE_STATE has changed, and also you see it hasn't changed when using MsgBox to show this property (AI_SERVICE_STATE) - so if it was last "Stopped", then it remains like that: even if it should have said: "Not Found".

Currently I found a way in my installer to "live with" the initial check only (at phase "LaunchConditions"), but I consider this a "patch" and would love to have this working for me when I need it (and not only at LaunchContidions).

Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,

Can you please send us the aip file and the verbose logs so we can investigate them? Also, please check that the custom action is not running as deferred, so it can access public properties without any problems.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

It's not running as deferred, but as "Deferred with no impersonation". I've changed my aip, so it will take me a while to give you the aip that I had before + logs.
Is there a way to talk to you somehow? Some things I'm experiencing here are driving my nuts...
For example: if I'm running an upgrade, and in the custom action I use condition: "(NOT OLDPRODUCTS)": should this custom action run at all when upgrading? I want to believe that no, but I experienced that yes... (for first time installation I want this custom action to run, but NOT for upgrades).

Another question: if the "LaunchConditions" is conditioned with "(Not Installed)" which I believe is the default: why do custom actions there that have no condition run TWICE! I would believe that "LaunchConditions" is run only once... but since it's running twice: how can I distinguish between the first run and the second?

Dashut.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,

We do not provide other kinds of support except on the forum and email. Customer support in this field takes time and research, providing real-time support is simply not feasible.
Regarding the OLDPRODUCTS property. To detect an upgrade, you use the OLDPRODUCTS property in the upgraded package, and the UPGRADINGPRODUCTCODE property in the target package.

Code: Select all

installer.msi (v1.0) use UPGRADINGPRODUCTCODE  in this one
installer.msi (v1.1) use OLDPRODUCTS  in this one
Another question: if the "LaunchConditions" is conditioned with "(Not Installed)" which I believe is the default: why do custom actions there that have no condition run TWICE! I would believe that "LaunchConditions" is run only once... but since it's running twice: how can I distinguish between the first run and the second?
LaunchConditions is a standard action. Its condition applies only to itself, not the custom actions under it. The custom actions will need to have their own condition.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

I force my users to have Windows Installer 4.5.
Keeping in mind that I'm using window installer v4.5: I still don't understand the difference between properties OLDPRODUCTS and UPGRADINGPRODUCTCODE.
You say:

Code: Select all

To detect an upgrade, you use the OLDPRODUCTS property in the upgraded package, and the UPGRADINGPRODUCTCODE property in the target package.
What do you mean "upgraded package"? and what do you mean when you say: "target package"?

For first time installation: both properties do NOT appear in the msi log files.
When upgrading: I see both properties in the msi log files.

Since I use ONE msi file to upgrade (after I have used a previous one of course for first time installation), then what's: "upgrading package" and what's "target package"?

Sorry this might sound basic to you, but I just didn't get it yet...
Thanks for all, Dashut.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,

When you are upgrading, there is already an installed package on the system. In this context, we refer to it as the target package. That package, during the uninstall sequence, will have the property UPGRADINGPRODUCTCODE set so that custom actions inside it can know that the package is being upgraded and adjust their behavior accordingly (like leaving user data behind so that the new version of the software being installed can use it, which is a typical behavior for many application installers).
The upgraded package is the package being installed on the system now, the one initiating the target package's uninstall. This upgraded package has the OLDPRODUCTS property set, indicating that its installation is removing a previous version of the software. Similarly, custom actions in this package can adjust their behavior accordingly, by using this property.

I am simply trying making sure you are using the correct property for the role your installer has in the upgrade process (either that of a target package, or an upgraded package).
Another important thing to note, and if I understood correctly, this might be what solves your issue: The OLDPRODUCTS property is only available after the FindRelatedProducts standard action was executed. If you are placing your custom action before this standard action, the condition will not work properly as OLDPRODUCTS is not set yet.

Let me know if that helps.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

Okay, this helps. I'll now go through my aip custom actions and make changes accordingly.

Another question:
I see for example in first time installation log (and this also happens in upgrades log) that a custom action is run, but it really didn't and it did in the second time.
It looks like this (taken from the msi log for first time installation of the product line: 4281):

Code: Select all

MSI (s) (84:E4) [01:14:55:288]: Doing action: RenameApacheErrorLogToErrorLogBak
Action 1:14:55: RenameApacheErrorLogToErrorLogBak. 
Action start 1:14:55: RenameApacheErrorLogToErrorLogBak.
RenameApacheErrorLogToErrorLogBak: 
Action ended 1:14:55: RenameApacheErrorLogToErrorLogBak. Return value 1.
and it really didn't run at this stage, but later on here (line: 13276):

Code: Select all

MSI (s) (84:E4) [01:16:43:140]: Executing op: ActionStart(Name=RenameApacheErrorLogToErrorLogBak,,)
Action 1:16:43: RenameApacheErrorLogToErrorLogBak. 
MSI (s) (84:E4) [01:16:43:140]: Executing op: CustomActionSchedule(Action=RenameApacheErrorLogToErrorLogBak,ActionType=3074,Source=BinaryData,Target=cmd.exe /C move /Y "C:\Program Files\Apache Group\Apache\logs\error.log" "C:\Program Files\Apache Group\Apache\logs\error.log.bak",)
notice the timestamps difference: [01:14:55:288] for the first and [01:16:43:140] for the second.

What's going on here?
Many thanks, Dashut.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,

The action is mentioned twice in the log because of the way non-immediate actions are executed:
1. First Windows Installer goes through all actions and creates a script which includes all actions that should be executed. Actions are not executed, but they are mentioned in the log.
2. After creating this script, all actions in it run one after another. This is also mentioned in the log.

You can read more about this in the Custom Actions article.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

Okay, makes sense. So just to see if I got it right: the first pass the Installer adds all custom actions without looking at the conditions, and in the second pass it actually runs them depending on the condition (that is: for non-immediate custom actions)?

Dashut.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,

Conditions are evaluated when the script is created (in the Immediate phase). Actions with false conditions are not included in the script. When the script runs, all actions in it are executed.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

That's weird, because then I can't use for example: your "detect service" in non-immediate, but only in immediate...
Because if I want in "Detect Service" in the non-immediate, and according to the result do some custom action: then from what you say this will NOT work.

Is this true? (this might also explain why "Detect Service" didn't work for me which is why I opened this ticket in the first place...).
Dashut.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,
That's weird, because then I can't use for example: your "detect service" in non-immediate, but only in immediate...
This is correct. Since this custom action sets an installer property based on a service state, it can run only as immediate. Only immediate custom actions have access to installer properties.

Like Bogdan mentioned in his first reply, please make sure that your custom action is not running as deferred ("Deferred with no impersonation" is still deferred). It should run as Immediate.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

Then this means that you have to revisit the link: http://www.advancedinstaller.com/user-g ... rvice.html
and update it to say that you can only run DetectService in immediate, and that then use AI_SERVICE_STATE wherever you want.
Because you currently have written:

Code: Select all

This custom action can be added at any point of the installation
Yes, you can run it when you want: but if your next custom action depends on the result of AI_SERVICE_STATE: then for non-immediate this will NOT work, since all non-immediate custom actions are evaluated before! (that's from what you said in this thread).

Your thoughts on this?
Dashut.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Detect Service (AI custom action) doesn't always work

Hi Dashut,
Then this means that you have to revisit the link: http://www.advancedinstaller.com/user-g ... rvice.html
and update it to say that you can only run DetectService in immediate, and that then use AI_SERVICE_STATE wherever you want.
We will update the how-to in a future version. Thank you for your suggestion.
Please note that the custom action properties article states that deferred actions do not have access to installer properties.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: Detect Service (AI custom action) doesn't always work

Cosmin:
That's completely true. That explains why "DetectService" will "not work" for non-immediate custom actions.
I think that if you had in your help database examples of *.aip projects of how to do things this could help a lot!

Okay, thanks again, Dashut.

Return to “Common Problems”