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

I'm trying to find how to query, change and add to the system environment variables on NT systems and i'm having trouble finding resources that can point me in the right direction. Can anyone help?

Replies are listed 'Best First'.
Re: Evironment variable on Win32 machines
by the_slycer (Chaplain) on Jun 20, 2001 at 20:40 UTC
    Environment variables on WinNT and 2000 are available through the %ENV hash. You can see them from a command prompt if you type 'set'.

    If you need to change environment variables permanently you can do so through the registry using Win32::TieRegistry. The keys are located at "HKML\SYSTEM\CurrentControlSet\Control\Session Manager\Environment".
(tye)Re: Evironment variable on Win32 machines
by tye (Sage) on Jun 20, 2001 at 21:18 UTC
Re: Evironment variable on Win32 machines
by TGI (Parson) on Jun 20, 2001 at 21:38 UTC

    An important note: In NT4 if you set an environment variable through the System Control Panel, it will not be available in DOS sessions until you logout and login again. I discovered this when I was doing a weird hand tweaked install of Indigo Perl (don't ask).

    Update Re: tye Perhaps it is peculiar to how our boxes are set up here, but clicking OK and/or Apply in the System CP has no effect on any current (no surprise there) or new command prompt windows (unless you logout/in). tye is right when he says a new window should have the proper environment settings. None of my employer's machines shows the reasonable behavior tye speaks of. YMMV. Don't you just love Windows.


    TGI says moo

      Actually, you don't have to log out and back in again. You can make the changes in the Registry however you like. Then go to the Control Panel -> System (-> Advanced) -> Environment. Click OK. Now the Explorer shell has been told to pick up the new environment settings (but the Service Control Manager hasn't, but that shouldn't matter for most cases). Now open a new Command Prompt window and the environment should reflect the changes. Command Prompt windows opened before the changes won't see the changes.

      Update: Regarding

      clicking OK and/or Apply in the System CP has no effect on any current (no surprise there) or new command prompt windows
      It sounds like you may not have followed the directions. You have to select the "Environment" tab (in WinNT) and then click "OK" ("Apply" won't be an option). In Win2K, you have to select the "Advanced" tab, open the "Environment" dialog, then click "OK".

      One more thing, you can't start a new command prompt from an old command prompt or it will inherit its environment from that command prompt instead of from the Explorer shell.

      I've just reverified this behavior for both WinNT and Win2K (starting the new command prompt window from the "Start" menu).

              - tye (but my friends call me "Tye")
Re: Evironment variable on Win32 machines
by IraTarball (Monk) on Jun 20, 2001 at 20:52 UTC
    I haven't used this but Dave Roth's book on Win32 scripting uses the Win32::AminMisc module to do this. He has code examples up on his web page. You want to look at Chapter 6.

    Good Luck!
    Ira

    "So... What do all these little arrows mean?"
    ~unknown

      Much thanks. I have Dave Roth's "Windows NT: Win32 Perl Programming" and it only touches lightly determining the current directory using environment variables.... I was in limbo on which one to buy at the book store.:) cheers, Ray