/build/static/layout/Breadcrumb_cap_w.png

If Statement true, set Environment Variable

Transitioning from Wise 9 Professional to WPS Standard.

Need to create an If Statement to check for the presence of a certain Registry Value. If the Value is present, I need to set an Environment Variable. This can be at the end of the installation of my Setup/Captured application. I can set an Env. Var., but not sure how to word the If Statement to do so conditionally.

0 Comments   [ + ] Show comments

Answers (10)

Posted by: captain_planet 15 years ago
Black Belt
0
Use the Environment table to set the environment variable. Then, perform a 'System Search' to store your chosen 'searching for' registry value inside a property - let's say the property is called 'CUSTOMREG'. Then, you could use this property as a condition on the component which puts down your environment variable. For example, the condition for the component would be: CUSTOMREG<>""

Therefore, if CUSTOMREG is not empty (reg key found), install the component (and set the env var), otherwise don't install the component (and thus don't set the env var).

Look into the Environment, AppSearch and RegLocator tables.....as well as the Condition column of the Component table.....
Posted by: anonymous_9363 15 years ago
Red Belt
0
That's pretty straightforward to do in WPS.

- select 'Setup Editor'
- click the 'Product' tab
- select 'Properties'
- right-click the right-hand pane
- select 'New/Property'
- enter, in all upper-case (making it a so-called Public property), a name for the property. I'd suggest making it "suggest" the registry data you're reading.
- enter a value. I normally use '0'

- select 'Installation Expert' view
- in 'Target System' pane, select 'System Search'
- click 'Add' in the right-hand window
- select 'Registry' and complete the dialog, selecting the property name you created. I imagine you'd want to select 'Read raw value from registry' for 'Operation'.
For reference, this populates the AppSearch and reglocator tables.

Once you have your component which sets the variable:

- select 'Setup Editor' view
- click the 'Components' tab
- locate the component which sets the environment varaible
- right-click the component and select 'Details'
- in the 'Condition' box, build the condition such that your property's value is NOT whatever you set it to when you created it. Remember I suggested 0? If you went with that, your condition would be 'If MYREGDATAPROPERTY <> 0'
Again, for reference, this alters the 'Condition' column of the 'Component' table row which contains your environment-setting component.

What happens on execution is your property's value gets populated by the contents of the registry entry, thus making it not match '0' and your environment variable gets set. If the registry entry isn't present, the property's value remains '0' and the environment variable isn't set.

I think I remembered everything...
Posted by: captain_planet 15 years ago
Black Belt
0
'If MYREGDATAPROPERTY <> 0' - are you writing your VBScript conditions again? Ha ha. [;)]
Posted by: Ron Duca 15 years ago
Senior Yellow Belt
0
Thanks for the info. The step-by-step instructions were very helpful, although I had to use some trial and error to build the condition statement.

Now I need to do the same thing for multiple conditions. In other words, if the registry value equals "A", I need the Env. Var. set to "VarA". And if the registry value is "B" or "C", I need the Env. Var. set to "VarB".

I tried doing this in a test project and it worked for "A", but I can't get the syntax correct for the "OR" statement. Here's what my "A" statement looks like:

'If SITENAME = A'

For the other statement I tried 'If SITENAME = B OR C' . I also tried putting B & C in double quotes. I even tried 'If SITENAME = B' OR 'If SITENAME = C' .

Any ideas?
Posted by: anonymous_9363 15 years ago
Red Belt
0
Use WPS's Condition Builder (click the 'Build' button next to the Condition field). Once you've done a few, you'll get the syntax. Plus, trial and error probably sums up the way I've picked up most of this junk!

Note that Windows Installer treats everything to right of the equals sign in conditions as a string so the condition

If Foo = 0

is the same as

If Foo="0"
Posted by: Ron Duca 15 years ago
Senior Yellow Belt
0
Once I do one I'll get the syntax. The problem is getting that first one to work.

Using the Condition Builder, I select Component in the Fields column. I then select Environment from the Values column. The Paste button does not light up unless I select a State (Action or Installed). Not sure which one to select there, if any, or if I should select an Install/Action state.

I don't see any "If" choices. Do I type that in there manually? And no matter what I end up with, I get a syntax error. Are there any good examples of various Condition statements that I can review?
Posted by: captain_planet 15 years ago
Black Belt
0
I don't see any "If" choices. Do I type that in there manually? - Ron, maybe my second post on this thread yesterday was too cryptic for you? How about:

SITENAME = "A"

SITENAME = "B" OR SITENAME = "C"
Posted by: Ron Duca 15 years ago
Senior Yellow Belt
0
OK. I just realized that when I create an Environment Variable, the condition gets created automatically. An example of one is If SITENAME = Houston .

Everything looks fine now. However, when I test the script by changing the site names in the registry, the resultant Env. Var. gets set to the same value every time, regardless of the site.

Here's what I did:

* Created a Property of SITENAME with a Value of 0

* Created a System Search to "Read raw value from registry" and put into the Property SITENAME

* Created five different Environment Variables

* In Setup Editor, I edited each Component. Here is an example of one:

Component: Environment
Directory: TARGETDIR
GUID: "default value"
Condition: If SITENAME = Houston
Run Location: Run Locally
Key Path Type: Registry Key Path
Reg. Key Path: <none>

The other four look the same except for the Condition, which reflects a different site for each. Am I missing something here? Why would I not get the correct Env. Vars. when I change the site name in the registry?
Posted by: anonymous_9363 15 years ago
Red Belt
0
An important point (which I omitted - sorry) is that you should avoid using System environment variables, as they are not propogated to all processes when they're updated. Could that be what's happening here?
Posted by: Ron Duca 15 years ago
Senior Yellow Belt
0
The msi is updating the "User variables" on my machine, rather than the "System variables". It's just not doing it properly. It appears to be using the first variable by alphabetical site, which in this case is Dallas. Even if I select Houston, I get the variable for Dallas. When I created the Env. Vars., I didn't create them in alphabetical order. Tulsa is actually the first one with an assigned name of "Environment". Dallas was the second one created with an assigned name of "Environment1".

I sure would like to figure this out and use the methods designed within WPS, but I'm not going to spend too much more time on it. I created an AutoIt script that works perfectly. I just need to figure out where to insert the command that will execute the script at the end of the installation.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ