Re: ENV variable NOT recognized ! Reboot really necessary ????



Camille Petersen wrote:
From what I have heard it is NOT necessary to reboot when I change an environment variable.
But much to my surprise WinXP did not recognize such a new env value otherwise!

Hi Camille

You can change environment variables at any time. However, this will only change the environment block for new processes created *after* the change. Existing processes will keep on using their current environment block, which is the same as it was before you made the change. New processes will inherit the changed environment.

A process can elect to update its environment block dynamically, by calling SetEnvironmentVarible(). But an application needs to be written to explicitly do this; there's no mechanism in the operating system to universally update environment variables on the fly for running processes.

For example, say you had a command prompt open, and you run a SET command to display the current variables. You will see what is in that instance of CMD.EXE's environment block. Now, update the environment variables via System Properties, Advanced, Environment Variables. Now open a new instance of the Command Prompt and type SET. Run SET again in the old Command Prompt. Compare the output of SET in the "before" and "after" Command Prompts. You will see that SET in the new Command Prompt will display the updated values for the variables; SET in the old Command Prompt continues to display the variables from before the change.

If you are running squirrel.bat from a Command Prompt, you would need to open a *new* Command Prompt after updating the environment variable, in order for the variable change to be recognised.


There are some additional subtleties around System vs User variables etc, but I think the above cuts to the heart of your problem.

The Windows shell application (usually Explorer.exe) listens for WM_SETTINGSCHANGE messages, and will update its copy of the environment dynamically.

Batch files aren't processes in their own right, they just run in the context of whatever application was used to start them - usually CMD.EXE. Otherwise, they inherit the environment from CSRSS.EXE.

See here for some official Microsoft doco, explaining in more detail:

http://msdn.microsoft.com/en-us/library/ms682653(VS.85).aspx

In summary, to make sure a changed environment is recognised, you need to launch a new process after the change. Generally, you should never *need* to reboot (although in some circumstances, that might be the easiest way to get an update recognised)

Hope it helps,

Andrew

--
amclar at optusnet dot com dot au
.



Relevant Pages

  • [REVS] Using Environment for Returning Into Lib C
    ... This article explains how to use the environment variables to successfully ... The environment will consequently be used to store it. ... It is easy to write a simple program to put the command directly into the ... declare -x COLORTERM="" ...
    (Securiteam)
  • Re: SSH environment variable passing
    ... has to be a capability of both the client and the server. ... to support only a couple of specific environment variables. ... I have been told that allowing unlimited environment variables to be set ... A parallel situation exists in telnet. ...
    (SSH)
  • Re: Multiple interpreters retaining huge amounts of memory
    ... environment variable separation for changes made unique to a sub ... you can make changes to environment variables ... extension module in different sub interpreters, ...
    (comp.lang.python)
  • Re: New "base document" available
    ... "The PRINTENV command is used to display environment variable ... Environment variables are a feature of the shell, ... then a configuration file, and then the environment or the registry. ... it is impossible to get a facility added to COBOL unless they ...
    (comp.lang.cobol)
  • Re: [Info-Ingres] getenv, NMgtAtt and OME
    ... that I can just toggle with an environment variable. ... It's all about context - your OME function is being called from the ... variable - just like how normal Ingres can look for user ... environment variables such as II_DATE_FORMAT etc... ...
    (comp.databases.ingres)

Loading