Refresh environment variables

  • Thread starter Thread starter cbmanica
  • Start date Start date
C

cbmanica

I have created a batch file that will add a certain directory to the
current user's PATH environment variable. When you update environment
variables from the control panel, they get "refreshed" and are
immediately visible to new processes; what I want is to "refresh" the
environment variables from the registry and accomplish the same thing
from a batch file. Is there a way to do that, or are my users
condemned to log off and log back on to see the changes to their PATH?
 
I have created a batch file that will add a certain directory to the
current user's PATH environment variable. When you update environment
variables from the control panel, they get "refreshed" and are
immediately visible to new processes; what I want is to "refresh" the
environment variables from the registry and accomplish the same thing
from a batch file. Is there a way to do that, or are my users
condemned to log off and log back on to see the changes to their PATH?

This is not quite the way it works. When you modify an environmental
variable such as %path% from within a batch file, using the "set" or
"path" command then this modified variable is valid only for the
current process. It is not valid for any other process and it will
disappear as soon as you close this process. If you wish to make
your change permanent then you have two options:

a) Set the variable via the Control Panel, or
b) Use setx.exe or setenv.exe

Note that both methods will have ***no effect*** on environmental
variables in pre-existing processes. They will only affect processes
that you launch ***after*** modifying the variable.

setx (Win2000 Resource Kit)
setenv (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)
 
Pegasus said:
This is not quite the way it works. When you modify an environmental
variable such as %path% from within a batch file, using the "set" or
"path" command then this modified variable is valid only for the
current process.

That's not what I'm doing. I'm using regedit's command-line switches
to modify the registry entries for HKEY_CURRENT_USER\Environment.
b) Use setx.exe or setenv.exe

setenv would probably do the trick, but our IT policies are too
restrictive for it to be an option here. I suppose I will just have to
be content with telling my users to log off and log back on. I wish M$
wouldn't force people to go purchase a stupid "Resource Kit" to
accomplish useful things with the OS, given how much it costs to begin
with.
 
http://support.microsoft.com/kb/104011/en-us

http://www.microsoft.com/downloads/...76-9BB9-4126-9761-BA8011FABF38&displaylang=en

That's not what I'm doing. I'm using regedit's command-line switches
to modify the registry entries for HKEY_CURRENT_USER\Environment.


setenv would probably do the trick, but our IT policies are too
restrictive for it to be an option here. I suppose I will just have to
be content with telling my users to log off and log back on. I wish M$
wouldn't force people to go purchase a stupid "Resource Kit" to
accomplish useful things with the OS, given how much it costs to begin
with.

Stupid? Sometimes it might be more productive to do a small
amount of googling instead of bashing bad, bad Microsoft.

How to propagate environment variables to the system -
http://support.microsoft.com/kb/104011/en-us

Windows XP Service Pack 2 Support Tools
The Windows Support Tools for Microsoft Windows XP are intended for use by
Microsoft support personnel and experienced users to assist in diagnosing
and resolving computer problems.
http://www.microsoft.com/downloads/...76-9BB9-4126-9761-BA8011FABF38&displaylang=en
(includes setx.exe, apparently free of charge)
 
Pegasus said:
How to propagate environment variables to the system -
http://support.microsoft.com/kb/104011/en-us

This is a batch file, not a Win32 application. Unless there is a way
to send messages with some command line tool - I'd be glad to learn
that there is - this page (which incidentally I did find in my
Googling) is not helpful in my situation.
Windows XP Service Pack 2 Support Tools
http://www.microsoft.com/downloads/...76-9BB9-4126-9761-BA8011FABF38&displaylang=en
(includes setx.exe, apparently free of charge)

I do stand corrected on (some) support tools being available free of
charge, but I'm not prepared to ask users to install them prior to
using the batch files I am creating. Unless I'm missing something, the
answer to the question "Can I do what I want without installing either
third-party software or additional Microsoft packages?" seems to be
"No", which I can live with.
 
This is a batch file, not a Win32 application. Unless there is a way
to send messages with some command line tool - I'd be glad to learn
that there is - this page (which incidentally I did find in my
Googling) is not helpful in my situation.


I do stand corrected on (some) support tools being available free of
charge, but I'm not prepared to ask users to install them prior to
using the batch files I am creating. Unless I'm missing something, the
answer to the question "Can I do what I want without installing either
third-party software or additional Microsoft packages?" seems to be
"No", which I can live with.

Your original question was: "Is there a way to do that, or are my users
condemned to log off and log back on to see the changes to their PATH?"
Setx.exe will obviously do this. It is not a package but a tool that can
be made accessible on the logon share (for example). There is no need
to install anything.
 
Pegasus said:
Your original question was: "Is there a way to do that, or are my users
condemned to log off and log back on to see the changes to their PATH?"
Setx.exe will obviously do this. It is not a package but a tool that can
be made accessible on the logon share (for example). There is no need
to install anything.

All right, I appreciate the advice. I apologize for being a bit surly
in this thread.
 
Back
Top