prerak6962
Posts: 112
Joined: Mon Dec 08, 2014 5:26 pm

Execute powershell inline script only if feature is selected for installation

Thu Jul 26, 2018 1:48 pm

Hello,
I have a scenario in my installer during in which I want to execute a powershell script (inline) if a particular feature is selected for installation in the "ConfigureDlg". to achieve this, I did the following things:
  • Added a custom action "Run Powershell Inline Script" with sequence (I need admin rights)
    Added it after "Add Resources" stage in Install Execution Stage
    Ticked all the 3 options under Execution Options
    Ticked "Install" and "Maintenance" under Execution Stage Condition
    Set the Condition to

    Code: Select all

    (VersionNT > 501) OR (VersionNT = 501 AND ServicePackLevel >= 2) AND ((&FeatureId = 3) AND NOT (!FeatureId = 3))
However, the script is executed even if I unselect the Feature from the "ConfigureDlg".
Is there anything that I am missing or doing wrong?

Thank you.

AI Version: 14.4.2 build 82742

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Execute powershell inline script only if feature is selected for installation

Fri Jul 27, 2018 10:07 am

Hello,

Everything you did is fine, except the condition. Your condition can be split up in two conditions:
A - VersionNT > 501
B - (VersionNT = 501 AND ServicePackLevel >= 2) AND ((&FeatureId = 3) AND NOT (!FeatureId = 3))
separated by the OR operator.

In this case, if one of your conditions is true, the custom action will always run. And the condition that is always true is probably VersionNT > 501 in this case, if you have a higher version of Windows than Windows XP.

In order to avoid that, you can set the condition as it follows:

Code: Select all

((VersionNT > 501) OR (VersionNT = 501 AND ServicePackLevel >= 2)) AND (&FeatureId = 3) AND NOT (!FeatureId = 3)
This way, we have separated it in two conditions:
A - ((VersionNT > 501) OR (VersionNT = 501 AND ServicePackLevel >= 2)) -> by adding two more parantheses.
B - (&FeatureId = 3) AND NOT (!FeatureId = 3)
now separated by the AND operator. In this case, the condition A will always be evaluated as true, the only thing remaining being condition B to be evaluated as true (if feature is selected)

Hope this helps!

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

prerak6962
Posts: 112
Joined: Mon Dec 08, 2014 5:26 pm

Re: Execute powershell inline script only if feature is selected for installation

Fri Jul 27, 2018 2:00 pm

Hi Catalin,

Yeah that helped.

Thanks a lot.
Prerak

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Execute powershell inline script only if feature is selected for installation

Fri Jul 27, 2018 2:30 pm

Hello Prerak,

You're welcome!

I'm glad you got this working!

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

Return to “Common Problems”