/build/static/layout/Breadcrumb_cap_w.png

Initializing a User Environment Variable

Hi Everyone,

This problem is not specific to any application, but its a request we have got. The request is to set a User Environment Variable on a XP machine. This user environment variable will have a network path. This network path is being fetched from the HKCU registry, which is pre-populated.

So I have a simple package which does the following :

1. Read the HKCU registry and get the value of that particular key.
2. Populate the user environment variable with that particular variable.

The only glitch here is that all packages get installed in System Account. So the system account does not have access to User profile registries. To counter that I do the above two steps with Active Setup (There are a couple of other files that need to be installed as well, so a MSI package is essential).

So after reboot the active setup works fine and even the User Environment variable is populated if you go and see in My Computer->properties->Advanced Options. But my requestor says that the Environment Variable is not intialized. What he means is that when he opens a command prompt window (CMD) and types "set", he is unable to see the User Environment Variable which he is able to see otherwise. To see that Environment Variable using the set command he has to log off and log in once again.

My question here is, What is actually meant by initializing an environment variable? I am getting the same results as my requestor, but also when I type echo %variable% on CMD I do get to see the vale that it should be populated with and apart from that I can go and physically see that it is set. So why is it not showing using set command?

I could think of a couple of ideas to get this done, I still need to try though :

1. Kill the explorer.exe and restart it at the time of reboot when my active setup executes.
2. Get the logged on user's SID and populate the HKCU entries before reboot (not too convinced on this option).

Please advise.

0 Comments   [ + ] Show comments

Answers (4)

Posted by: kardock 14 years ago
Second Degree Green Belt
0
there is an option to refresh the variables after it is set. i don't remember it though, but a google search should help you. that would be your best option i believe.
Posted by: michaelnowell 14 years ago
Second Degree Blue Belt
0
You could use a custom action and execute the file 'setx.exe' (search for it on google) with the relevant command line parameters.
Posted by: michaelnowell 14 years ago
Second Degree Blue Belt
0
You can also try the the command "RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True" (found here http://www.appdeploy.com/messageboards/printable.asp?m=5315), but if you're using Win 7, this is no longer supported.
Posted by: aogilmor 14 years ago
9th Degree Black Belt
0
You could probably just populate HKEY_CURRENT_USER\Environment with your env var and use active setup to apply it to each user as they log on.
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