Set Permanent ENV variables on Windows

P

Prabh

Hello all,
Could anyone tell me how to set a Windows environment permanently?
I need to set the PATH variable from my Perl script and any changes I
make to this variable last only for the duration of my script's
running.

I realize Perl inherits a copy of the system ENV. and any changes made
to it are temporary, but heres my question, the install programs for
various products, Windows Installers, .msis, Setup.exes all make
permanent changes to the PATH variable when the product is installed.
Obviously, the changes made by these installers are permanent.

I just want to replicate this process from Perl.
Could anone give me some pointers, please?

Thanks for your time,
Prab
 
A

A. Sinan Unur

(e-mail address removed) (Prabh) wrote in @posting.google.com:
Hello all,
Could anyone tell me how to set a Windows environment permanently?
I need to set the PATH variable from my Perl script and any changes I
make to this variable last only for the duration of my script's
running.

I realize Perl inherits a copy of the system ENV. and any changes made
to it are temporary, but heres my question, the install programs for
various products, Windows Installers, .msis, Setup.exes all make
permanent changes to the PATH variable when the product is installed.
Obviously, the changes made by these installers are permanent.

I just want to replicate this process from Perl.
Could anone give me some pointers, please?

What version of Windows are we talking about?

In XP, you would modify the registry entry corresponding to the user
path:

HKEY_CURRENT_USER\Environment

You can add or modify the PATH variable under that key. Changes will not
take effect in the current cmd shell.

HTH
 
M

Mark Bole

Prabh said:
Hello all,
Could anyone tell me how to set a Windows environment permanently?
I need to set the PATH variable from my Perl script and any changes I
make to this variable last only for the duration of my script's
running.

I realize Perl inherits a copy of the system ENV. and any changes made
to it are temporary, but heres my question, the install programs for
various products, Windows Installers, .msis, Setup.exes all make
permanent changes to the PATH variable when the product is installed.
Obviously, the changes made by these installers are permanent.

I just want to replicate this process from Perl.
Could anone give me some pointers, please?

Thanks for your time,
Prab

In W2K, right click "My Computer", then click "Properties", "Advanced",
"Environment Variables". You can permanently set variables for both the
current user and the system (if you have admin privileges, I suppose).

--Mark Bole
 
K

Kevin Collins

Hello all,
Could anyone tell me how to set a Windows environment permanently?
I need to set the PATH variable from my Perl script and any changes I
make to this variable last only for the duration of my script's
running.

I realize Perl inherits a copy of the system ENV. and any changes made
to it are temporary, but heres my question, the install programs for
various products, Windows Installers, .msis, Setup.exes all make
permanent changes to the PATH variable when the product is installed.
Obviously, the changes made by these installers are permanent.

I just want to replicate this process from Perl.
Could anone give me some pointers, please?

Thanks for your time,
Prab

This would probably be better asked in a Windows forum... A quick search in my
WinXP help on 'PATH' came up with help on the PATH command. That help mentions:

"When started from a shortcut, Cmd.exe inherits the environment variables set
in My Computer/Properties/Advanced/Environment."

So, I searched my registry with regedit for "environment" and found the key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

Which has a entry called "Path" containing the system's defailt PATH setting.

So, if you want to change it system-wide, this is a good place to do that....

Kevin
 
A

A. Sinan Unur

(e-mail address removed) (Kevin Collins) wrote in
....

So, I searched my registry with regedit for "environment" and found
the key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session
Manager\Environment

Which has a entry called "Path" containing the system's defailt PATH
setting.

So, if you want to change it system-wide, this is a good place to do
that....

No it is not. Needs to be done in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
\Environment

if you want it system-wide. But, the current user may not have the
correct rights. Not all of us run XP as Administrators, you know.

I do not know the OP's main purpose. But, if this is an installation
related issue, then appending to the user's path is appropriate. OTOH,
this sort of task is probably better handled using one of the free
installers which would give the user to properly undo the changes made
during installation.
 
P

Prabh

[snipped]
No it is not. Needs to be done in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
\Environment

if you want it system-wide. But, the current user may not have the
correct rights. Not all of us run XP as Administrators, you know.

I do not know the OP's main purpose. But, if this is an installation
related issue, then appending to the user's path is appropriate. OTOH,
this sort of task is probably better handled using one of the free
installers which would give the user to properly undo the changes made
during installation.





Thanks a lot everyone for your posts.
I was able to set a system variable from your suggestions.

I was working on two programs, one where it can be safely assumed that
the user has admin rights and can set the System variables. The other
one needs to set the "user" variable.

From the XP, Control panel, System, Advanced, Env variables, I set the
"Foo = Bar" just to see where its put in the registry.
Its placed under [HKEY_USERS\"weird-hexadecimal-number"\Environment].

How can I generate this weird number so that I could programmatically
set the user variable? What local variable got interpolated to
generate this number?

Thanks a lot for your time,
Prabh
 
A

A. Sinan Unur

(e-mail address removed) (Prabh) wrote in
[snipped]
No it is not. Needs to be done in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
\Environment

if you want it system-wide. But, the current user may not have the
correct rights. Not all of us run XP as Administrators, you know.
....

From the XP, Control panel, System, Advanced, Env variables, I set the
"Foo = Bar" just to see where its put in the registry.
Its placed under [HKEY_USERS\"weird-hexadecimal-number"\Environment].

This is getting way OT here. You are missing the very very obvious:

HKEY_CURRENT_USER\Environment

Sinan.
 

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

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top