Unless you want the entire registry reloaded, you could do it in two steps: first add it to the registry as you are doing, then set $ENV{POS_SYS} = "G=DEPT99 D=99 N=MGR" for the environment in the current login.
Main Topics
Browse All TopicsI'm trying to set an environment var and have it persist after the perl script ends. Setting the ENV var via Win32::TieRegistry is easy, however, unless I logout/login that environment setting isn't available to other processes. So, the question is: how do you reload the registry without having to logout?
For background context, this is part of a Tk login script that upon authentication, will launch a batch file via exec. So, the final solution could be either Perl related or a windows command executed in the batch file
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry, I guess I wasn't clear enough. I'm not concerned with the current running process. I need it to be persistent. Meaning that If I open a new cmd window after running the test script, I should be able to utilize that ENV setting.
If you run the test script (with or without manually assigning $ENV{POS_SYS} and check your env via "My Computer"->Settings->Envir
Here's the results I get after adding the ENV assignment as you suggest.
Unfortunately, that suffers from the same problem as setting it in HKEY_CURRENT_USER i.e., it still requires a logout/login to take effect. Additionally, setting it in HKEY_LOCAL_MACHINE creates the secondary issue of being applied to all user accounts.
I've also been informed of a change in the requirements. This environment setting needs to be applied only to the current user and should not be retained across logins/reboots. I've found a setx command in the Windows Resource Kit that propagates the environment setting for any newly started processes without the need to logout/login, which solves the first part of the problem. Unfortunately, the setting is retained across logins/reboots.
I just tried that code again, and it didn't work - and I was sure it worked before - thought I was going crazy.
A little more testing, and I found out if I run that code, then start a new process, it does NOT have the new environment variable. After a while, doing other things on the computer (but never logging out), I start a new process, and it DOES have the new environment variable. So it seems that something will cause windows to re-read the registry without logging out/in. Not sure what that is... still looking. I have found that if i right-click my computer, select properties, select advanced tab, click environment variables (don't change anything), click OK, this always seems to cause windows to reload the environment from registry. I didn't do that before, and the new environment variable was processed, so there must be other things that cause it also.
I'm running XP Pro, SP2. Can you test and see if you get the same behavior?
I also found this key in the registry:
HKEY_CURRENT_USER/Volatile
But setting things there does not seem to take effect, at least not with what I've been doing.
I think I found out why the setting was taking (immediate) effect and a possible solution, but I'm still testing.
http://barnyard.syr.edu/%7
Business Accounts
Answer for Membership
by: FishMongerPosted on 2008-04-01 at 20:10:47ID: 21259928
Here's my test script.
Select allOpen in new window