Environment variable: System versus User - Advanced Installer Community
tatistcheff
Posts: 2
Joined: Tue Aug 13, 2019 12:41 pm

Environment variable: System versus User

How can I print both the system value and machine value of an environment variable in a dialog?

Our users have the option of setting environment variable MYTHING as a system variable, user variable, or not at all (one typical example of this is the TEMP variable). To decide what to do, they need to know the values that are currently set.

In a custom dialog, I am able to print out the resolved value of MYTHING by using [%MYTHING] in the text field. I haven't found a way to reference the unresolved value, however.

I am able to get the user and machine values individually in powershell, sticking them in a variable as follows:

Code: Select all

$systhing = [Environment]::getEnvironmentVariable("MYTHING", "Machine")
$usrthing = [Environment]::getEnvironmentVariable("MYTHING", "User")
if ($systhing -eq "") {$somestring = "SYSTEM: Not set`n"} else {$somestring = "SYSTEM: " + $systhing + "`n"}
if ($usrthing -eq "") {$somestring += "USER: Not set"} else {$somestring += "USER: " + $usrthing}
But I am not seeing how to then use $somestring as a the contents of a dialog text field.

Thanking you in advance!
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Environment variable: System versus User

Hello and welcome to Advanced Installer forums,
But I am not seeing how to then use $somestring as a the contents of a dialog text field.
In order to achieve this, you can save the value of your variable in a property. Please have a look on our "PowerShell inline script" article for more information how you can get and set a property's value using PowerShell.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
tatistcheff
Posts: 2
Joined: Tue Aug 13, 2019 12:41 pm

Re: Environment variable: System versus User

Thank you, Catalin. This is exactly what I was looking for.
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Environment variable: System versus User

You are always welcome.

I am glad I could help.

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

Return to “Common Problems”