Click to See Complete Forum and Search --> : SetEnvironmentVariable
I am trying to set an environment variable in NT using the SetEnvironmentVariable(name, value) function and when I execute the code, it doesn't change the variable value. I have done what it says in the KB, including declaring the function in my module, and calling the function in my executed part of my code. Is there another way I should be doing this?
Thanks in advance for any help.
Ryan
RudolfS
June 4th, 1999, 07:07 AM
You can't use Envir.Var in the same way as in Win 3.11 or DOS. In NT each App gets his own World and therfore its own Environment. After closing an App (Thread) the Environment is cleared and the next App gets the Environment as is defined by starting up Win NT. Therfore you can't pass this Variables to the next App. have a look in the Registry or INI-Files to solve your Problem.
RudolfS
rx39832
June 4th, 1999, 08:31 AM
I am using IBM's MQ series on this box also. To get MQ to work, you have to set an environment variable in NT that is called MQSERVER. I would like to set the value of this variable on startup of my thread. I am achieving this by reading an INI file that loads variable in my app and then I am trying to assign the INI value to the MQSERVER environment variable in the FormLoad sub. Is this possible? I don't want to pass the variable to the next app, I just want to set the environment variable at startup.
RudolfS
June 4th, 1999, 08:37 AM
The Problem is if the second App runs in the same thread. i don't know MQSERVER. if it runs in the thread of your APP you can set the Envir.Var in your APP, but if not you have to make changes in the Script that runs at boot-time of your computer. Maybe you can change autoexec.bat
Rudolf
rx39832
June 4th, 1999, 08:49 AM
That is what I guess I am struggling with. I can change the value on the fly (without rebooting) using the NT system properties applet (which does affect MQ), but when I try to do it using the SetEnvironmentVariable call, it doesn't take effect. Maybe this is not what the function is designed for.
RudolfS
June 4th, 1999, 09:01 AM
it seems we have a new paradigm in 32-bit os's. in 16-bit World you have en Environment for all processes. Each change was reflected ba all processes and you are able to say "SetLocal" and have your own Environment that was thrown away at end of process or with "EndLocal". Now you have an Environmet you cannot change and are automatically in the old "Local" state. All my App that uses Env.Var's are blown in the wind
Be happy
RudolfS
rx39832
June 4th, 1999, 11:04 AM
Final Answer:
Each process gets it's own copy of the environment variables when it is started. Each process (or application) can then manipulate it's copy of the environment without effecting other processes. When the process ends, it's environment variables are thrown away.
One exception to this is if your application starts another application, it will inherit your applications environment variables. This can be used to pass information to another application.
In summary, environment variables are only used for the duration of the thread, and will default back to the NT system property value when the thread is finished executing.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.