Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Updating Microsoft Windows (win32) environment variables

by kirk123 (Beadle)
on Apr 29, 2003 at 14:51 UTC ( [id://253957]=perlquestion: print w/replies, xml ) Need Help??

kirk123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Is there a way to permanently update window environment variables through a perl script. For example "PATH=c:\h;".
--thanks

2003-04-28 edit ybiC: retitle to make OS evident

Replies are listed 'Best First'.
Re: Updating window environment variables (CleanPath)
by tye (Sage) on Apr 29, 2003 at 15:13 UTC

    See CleanPath. Though I don't think it works for Win9x.

    Figuring out from that code how to change other environment variables permanently should not be difficult.

    Sorry, I never did figure exactly how you are supposed to set environment variables on Win9x. If you are running that, then you'll probably just have to update AutoExec.bat.

                    - tye
Re: Updating window environment variables
by smitz (Chaplain) on Apr 29, 2003 at 15:06 UTC
    Not sure quite sure what you mean by permanently, but maybe these will help:
    • Really Permanently: Why not go through Settings -> Control Panel -> System -> Advanced -> Environment Variables?
    • Win32::Registry The keys you are looking for are:
      1. HKCU\Environment - User (saved between logons)
      2. HKLM\System\CurrentControlSet\Control\Session Manager\Environment - System
      3. HKCU\VolatileEnvironment - User (not saved between logons)
    • Meta::Utils::Env: May work for you, check the docs.
    Hope these help,

    Smitz
Re: Updating window environment variables
by Improv (Pilgrim) on Apr 29, 2003 at 14:56 UTC
    Could you clarify what you mean? If you want to change them for every bootup, you can toss this into your AUTOEXEC.BAT:
    PATH=%PATH%;C:\h
    If you're just talking about for the current program, you can modify %ENV. Or are you talking about modifying it for whoever runs your script?
Re: Updating Microsoft Windows (win32) environment variables
by lpoht (Sexton) on Jul 13, 2003 at 20:26 UTC
    As far as I know, you have to restart the computer for System Environment Variables to take effect.

      You only need to (re-) start the processes that you need to see the new System Environment vars, after changes are made through the ControlPanel->System->environmentTab or directly through the registry.

      For example. If you have a CMD window open, it won't see changes made whilst it is open, but if you open a new one (via the Start menu short cut!) it will.

      However, if you start a new window from an existing one using START, then that new session will inherit its environment from the existing window and so will not see any changes made through the control panel or the registry since the original window was opened. That is, unless you use the /I switch on the START command, in which case it will get a fresh copy complete with changes.

      The same is true for any other applications running when the change is made. They will not see those changes as their copy of the environment was created when they were. Whether any child processes they spawn will see changes will depend upon what flags the app uses when is calls CreateProcess.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://253957]
Approved by smitz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-28 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found