cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
RayKode
Level 6

How to resolve Environmental variables

Hello everyone,

Here's the deal.
My application installation program (created by InstallShield Professional 2009) asks the person performing the installation to enter the path and folder name of where they would like the application installed.

Makes sense so far.

And as long as the person performing the installation enters an explicit path, IE: C:\Bob, C:\Program Files\Ray, etc, everything works great.

Recently it has been brought to my attention that a client of ours tried, unsuccessfully, to enter an environmental variable such as %AppData% or %USERNAME% when asked to enter where they wanted to install the application.

But it appears as if this value was handled as an explicit value.
In other words, InstallShield did NOT resolve %AppData% or %USERNAME%, automatically.

Is there an InstallShield function that, will resolve these variables?
IE:
I pass a string that was entered by the person performing the installation to this InstallShield function and this function passes back the resolved string.
Which I would then, move into “INSTALLDIR”.

Or, how would one go about resolving these variables so that ultimately, “INSTALLDIR” might be populated with the fully qualified path to where the person performing the installation wants to install my application?

Thanks in advance.

Ray in Wisconsin
Labels (1)
0 Kudos
(2) Replies
MGarrett
Level 6

I don't recommend letting users do this, but it may be possible using InstallScript.
If this is an InstallScript installation, you can use the function
GetEnvVar(szParameter, svValue)
to get the current value of the environment variable.

You would have to manually parse out the variable between the % symbols, pass it to GetEnvVar, and then substitute the value back into the path. Don't forget your error checking to be sure that the user specified a valid environment variable.
0 Kudos
RayKode
Level 6

Here's how I did it, in case anyone else, ever needs to do such a thing.

To recap:
Our product gets installed into a parent product on the destination pc.
How do I know where to install it ?
I read a very specific registry who’s value data contains a path to the parent product installation folder.

As long as the path is explicit, (C:\Program Files\Parent folder or any such nonsense like this) then everything works great.
But some pcs, have environmental variables within the registries value data.
(“%PROGRAMFILES&\Parent folder” or “%AppData%\Parent folder”.)

First:
First thing I needed to do was stop using a “System Search” to retrieve the value of the above referred to registry key.
Why ?
Cuz System search, for some reason, wants to validate the value data that is found.
System search returns an error message (Error 1606. Could not access network location %PROGRAMFILES\Parent folder”.
(I tried several other environmental variables and received a similar 1606 message. (although the content of the dialog was different depending on which I used.)

So anyway, I created an InstallScript custom action that called an InstallScript function that read the registry and populated a property with what it found.


Second:
The second thing I needed to do was created another custom action.
This time it was a VBScript custom action (stored in the custom action)
.
Which basically read the information from the property populated by my first (InstallScript) ca and then resolved all environmental variables that might be present within this property.
The last thing this second CA does is populate the INSTALLDIR property with resolved value.

IE:
“%PROGRAMFILES%\Parent folder” will resolved to “C:\Program Files\Parent folder”.
“%AppData%\Parent folder” will resolve to “C:\Documents and Settings\User1\Application Data\Program Files\Parent folder”.
You “get” the idea.

And things work great if it is on a Vista box as well. (Cuz user profiles are inside of the “Users” folder.)


I run both CAs right before AppSearch in both the Ui and Execute sequence.

Here’s what my VBScript CA looks like. (in case anyone is interested.)

Set WshShell = CreateObject("WScript.Shell")
Session.Property("strOriginalString") = Session.Property("REGISTRYVALUE")  “REGISTRYVALUE” is what was populated by my InstallScript CA.
Session.Property("strExpandedString") = WshShell.ExpandEnvironmentStrings(Session.Property("strOriginalString"))
Session.Property("INSTALLDIR") = Session.Property("strExpandedString")

When the above was done ….

If the original registry value contained “%PROGRAMFILES%\Parent folder”, INSTALLDIR contained “C:\Program Files\Parent folder”.
If the original registry value contained “%AppData%\Parent folder”, INSTALLDIR contained “C:\Documents and Settings\User1\Application Data\Program Files\Parent folder”.

Ray in Wisconsin
0 Kudos