Balaji
Posts: 53
Joined: Wed May 06, 2020 9:15 am

how to read environment variable value from system

Hi,
I hope you are doing well.
We are working on bootstrapper, in this case we have prepared one bootstrapper and we have one requirement as :

Requirement :

Read environment variable value from system using bootstrapper.

If suppose there is one environment variable "Developer Name" = "Balaji";
and I want to read value of "Developer Name" using bootstrapper.

Will you help us to achieve above requirement ?

Thanks,
Balaji
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: how to read environment variable value from system

Hello Balaji,

I am afraid we do not offer predefined support for your task.

However, you can achieve what you need through a custom action.

For instance, you can use PowerShell together with the Environment.GetEnvironmentVariable Method.

A one liner that retrieves the value of an environment variable may look like this:

Code: Select all

$var = [Environment]::GetEnvironmentVariable('variableName','scope')
Where "scope" represents where the script should look for the environment variable. The two posibilities are:

- Machine --> for system environment variables

- User --> for user environment variables

This can be implemented in Advanced Installer through a "PowerShell Script Inline" custom action.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
akshay karambale
Posts: 49
Joined: Thu May 28, 2020 8:04 am

Re: how to read environment variable value from system

Hi Dan,
Thanks for the reply. We have gone through your reply and also tried the way you suggested, but unable to get the value of the environment. Can you please describe more so that I can achieve this scenario? I have attached the screenshot of my script that I have written, and also please suggest how to use that value in the install parameter or assign that value to the install parameter.

Thanks
Akshay
Attachments
Powershellscript.JPG
Powershellscript.JPG (74.62 KiB) Viewed 5708 times
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: how to read environment variable value from system

Hello Akshay,
We have gone through your reply and also tried the way you suggested, but unable to get the value of the environment
How have you guys checked this? Judging by the provided screenshot, everything should be working as expected.

Are you trying to get the value of an environment variable that is created by your setup?

If that is the case, please note that your custom action should have the "Execution Time" set to "When the system is being modified (deferred)" and it should be scheduled after the "Add resources" action group (you guys are already doing this).

In order to set an installer property in a custom action, please refer to our "How to set an installer property using custom actions" article.

Please note that it is possible to set an installer property only during the "Immediate" stage of the installation process. With that being said, if your custom action has its' "Execution Time" set to "When the system is being modified (deferred)", it is not possible to a property's value from it.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
akshay karambale
Posts: 49
Joined: Thu May 28, 2020 8:04 am

Re: how to read environment variable value from system

Hi Dan,
Thanks for this reply. It resolves our UI based installation requirement. Here we have added that PowerShellScriptInline custom action in the Wizard dialog stage of the AIP project, due to which it executes this Powershell script during UI-based installation. But we want that PowerShell script also executes during Command-line installation. Is it possible that the PowerShell script will execute for both UI based and Command-line/silent installation? How we can achieve this?

Thanks
Akshay
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: how to read environment variable value from system

Hello Akshay,

Yes, it is possible to achieve that.

We will need to share the custom action between the two stages. To do so, please proceed as it follows:

- go to "Custom Actions" page

- select your custom action

- press the "Sequence Share" button from the toolbar

- select the sequence where you want to share the custom action (in this case, it would be "Install Execution Stage")

- after doing so, please select the shared custom action from under "Install Execute Sequence"

- under "Execution Stage Condition" please click on the "Advanced execution scenarios..." hyperlink button. From the menu, please select the "Skip action in Install Execution Stage if executed in Dialogs Stage".

This way, the custom action should only be executed during a silent install. During a full UI install, the action will be skipped in the "Install Execution Stage" since it was executed in the "Wizard Dialogs Stage".

ca.png
ca.png (322 KiB) Viewed 5686 times

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
akshay karambale
Posts: 49
Joined: Thu May 28, 2020 8:04 am

Re: how to read environment variable value from system

Hi Dan,
Thanks for the reply, But we have used the PowershellScriptInline custom action not the PowerShellScriptFile. Is it applicable to PowershellScriptInline? because we are not able to find the Advanced execution scenarios under this.
Please give us your view of this.

Waiting for your reply.
Thanks
Akshay
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: how to read environment variable value from system

Hello Akshay,

Yes, this is available for the PowerShellScriptInline custom action as well.
ScriptInline.png
ScriptInline.png (103.24 KiB) Viewed 5666 times

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

Return to “Common Problems”