I added some Environment Variables to my Windows operating system recently (right-click on My Computer, Properties, Advanced, Environment Variables). I was wondering if there is any way from an existing Command Prompt to pick those up. I know that all Command Prompt instances after this point will have those new environment variables defined, but I was just curious if there was an easy way to get an existing Command Prompt instance to “re-source” its environment variables.

On the other hand, is there any way to add a System Environment Variable to Windows from the command prompt?

§396 · October 3, 2007 · Microsoft, Questions, Software, Technology, Tips, Windows · Tags: · [Print]

2 Comments to “Re-Sourcing Environment Variables in Windows”

  1. Phil Deets says:

    I don’t know of a way to refresh the variables in a cmd session. I personally prefer not to mess with environment variables through the windows interface. I normally only declare temporary variables in my session. In case you don’t know, you can use the SET command to set variables for the current cmd session.

    For example, rather than load up my Path variable with loads of folders, I use a batch file called load.bat. Here is an shorted version of the code:

    @echo off

    if /I %1 equ vc8 goto vc8

    if /I %1 equ djgpp goto djgpp

    if /I %1 equ nasm goto nasm

    goto end


    if loaded equ %VC8LOADED% goto end

    set VC8LOADED=loaded

    set INCLUDE=

    set LIB=

    call “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat”

    goto end


    echo DJGPP

    if loaded equ %DJGPPLOADED% goto end

    set DJGPPLOADED=loaded

    set PATH=c:\djgpp\bin;%PATH%

    set DJGPP=c:\djgpp\djgpp.env

    goto end


    echo NASM 0.98.39

    if loaded equ %NASMLOADED% goto end

    set NASMLOADED=loaded

    set Path=C:\Tech\Assembly\nasm-0.98.39;%Path%

    goto end


    @echo on

    This shows how you can set environment variables within the session.

    With this file, I can type

    load djgpp

    gcc main.c

    gcc is not on the path until load.bat modifies the path variable to include its folder. This modified path variable is only modified on the session which called load.


  2. tabrez says:

    Phil, that’s a nifty little script!