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

  • Thread starter Camille Petersen
  • Start date
C

Camille Petersen

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!

I switched in
Control Panel->System->advanced->EnvVar

the User variable JAVA_HOME for an installation of Squirrel database.

After that I started (again and many times) the batch script squirrel.bat which shows still the old value
for JAVA_HOME. This is weired.

The only way to force WinXP to pass the correct value for JAVA_HOME to the batch script was to reboot.

Is there a trick/rule when a reboot is necessary and when not?

Camille
 
P

Pegasus [MVP]

Camille Petersen said:
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!

I switched in
Control Panel->System->advanced->EnvVar

the User variable JAVA_HOME for an installation of Squirrel database.

After that I started (again and many times) the batch script squirrel.bat
which shows still the old value
for JAVA_HOME. This is weired.

The only way to force WinXP to pass the correct value for JAVA_HOME to the
batch script was to reboot.

Is there a trick/rule when a reboot is necessary and when not?

Camille

No, a reboot is usually not required. Here is how it works:
- Each new process inherits its environmental variables from its parent.
- An active process will remain unaware of changes to the parent's
variables.

It follows that you must observe this sequence when changing a variable:
1. Change the variable in the Control Panel.
2. Terminate, then relaunch the process that makes use of the variable.

And here is how to test it:
Step 1: Create this System variable via the Control Panel: cam=Test1
Step 2: Click Start / Run
Step 3: Type cmd and press Enter
Step 4: Type this command and press Enter:
set cam
You should see "Test1".
Step 5: Modify the variable "cam" via the Control Panel: cam=Test2
Step 6: Click Start / Run
Step 7: Type cmd and press Enter
Step 8: Type this command and press Enter:
set cam
You should see "Test2".

If you still have a problem with Java then this is because you never killed
the Java process that makes use of Java_Home.
 
J

Jose

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!

I switched in
Control Panel->System->advanced->EnvVar

the User variable JAVA_HOME for an installation of Squirrel database.

After that I started (again and many times) the batch script squirrel.batwhich shows still the old value
for JAVA_HOME. This is weired.

The only way to force WinXP to pass the correct value for JAVA_HOME to the batch script was to reboot.

Is there a trick/rule when a reboot is necessary and when not?

Camille

I con't understand your method, but on your desktop, right click My
Computer, Properties, Environment Variables (near the bottom).

You have User and System variables, so add yours as needed, plus you
can view the ones that are there. Add a new one, click OK, etc.

Reboot once just to satisfy yourself it is really there when you check
again.

If you click Start, Run cmd <enter> to get to a command window, you
can type "set" to see all the variables.

If it is missing when you check, something went wrong.
 
A

Andrew McLaren

Camille said:
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
 
V

VanguardLH

NOTE: FollowUp-To header used by poster was ignored. My reply was sent
to all the original newsgroups. If a group is not adequate to continue
the discussion then don't post there. It is rude to include a group
but then yank away the discussion.

Camille said:
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! I switched in Control
Panel->System->advanced->EnvVar the User variable JAVA_HOME for an
installation of Squirrel database.

After that I started (again and many times) the batch script
squirrel.bat which shows still the old value for JAVA_HOME. This is
weired. The only way to force WinXP to pass the correct value for
JAVA_HOME to the batch script was to reboot. Is there a trick/rule
when a reboot is necessary and when not?

Did the batch file run successfully each time after the reboot?

When you add/change/delete an environment variable, the changes take
effect in subsequent NEW shells. That means if you had a DOS shell
open that the changes you made would not get applied to that already
existing shell. You will have to exit that DOS shell and open a new
one for it to read the newly changed registry keys where those
environment variables are stored.
 
T

Tim Meddick

We had a similar discussion on the group
"microsoft.public.win2000.cmdprompt.admin".

It turns out that after you change an 'Environment Variable' and you
close the 'System Control Panel', you then need to close ALL open
instances of 'Windows Explorer' PLUS close all open instances of the
'Windows Command Prompt' (cmd.exe)!

Then, the changed environment variable is taken up by all future
processes that use system variables.

==

Cheers, Tim Meddick, Peckham, London. :)
 
J

Jose

We had a similar discussion on the group
"microsoft.public.win2000.cmdprompt.admin".

It turns out that after you change an 'Environment Variable' and you
close the 'System Control Panel', you then need to close ALL open
instances of 'Windows Explorer' PLUS close all open instances of the
'Windows Command Prompt' (cmd.exe)!

Then, the changed environment variable is taken up by all future
processes that use system variables.

==

Cheers,    Tim Meddick,    Peckham, London.    :)

That's the way it has always worked.

I open a command window and look at my variables.

I change/set one and it stays that way until I close the window. Open
the window again, it is gone (of course).

I open a command window and then change/set a variable though Control
Panel or whatever method. My open command window will not see it -
why should it?

If I close my command window and open a new one, the variable
manipulated though CP or whatever method is now there.

Why should any running application see that kind of change after it is
already running and has already read its environment? You have to
restart it so it will read the variables again.

Working as designed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top