How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine

Reload this page Environment Variables

Here are my notes on setting up Environment Variables on Microsoft Windows and (in the future) other operating systems.

War drums is my theme music for this topic.

 

Topics this page:

  • On MS Windows
  • Oracle App Variables
  • Changing Win Vars
  • MS PATH
  • On Linux/Solaris
  • Java Variables
  • Amazon EC2
  • T-SQL Read
  • Your comments???
  •  

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page


    Set this at top of window. What Are Environment Variables?

      Environment Variables are stored in a small area of memory available to all programs running within or on top of the DOS environment (including Windows). They are called “variables” because they can be changed. In fact, some variables need to be reestablished after every reboot.

    • Variable names are NOT case sensitive within Windows.
    • For the Ruby language, Facter stores and retrieves "facts" from operating systems.

     

    Related:

  • Escape Characters
  • Java Architecture
  • Windows 2000 Installation
  • Windows 2000 Configuration
  • Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Windows System Environment Variables

      These system environment variables are automatically created by Windows upon boot-up in Windows Registry key HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Session Manager\ Environment

      Variable Sample Typical Value
      %SystemDrive% C:
      %SystemRoot% C:\WINDOWS
      C:\WINNT
      %WinDir% C:\WINDOWS
      C:\WINNT
      %SystemDirectory% C:\WINDOWS\System32
      C:\WINNT\System32
      %ComSpec% C:\WINDOWS\system32\cmd.exe
      The path including the command interpreter program.
      %programfiles% C:\WINDOWS\Program Files
      %Temp% C:\Users\W\AppData\Local\Temp on Windows Vista & 2008
      C:\DOCUME~1\Usr\LOCALS~1\Temp (compressed form of)
      C:\Documents and Settings\Usr\Local Settings\Temp
      %Tmp%
      %HOMEDRIVE% C: The drive letter associated with the user's home directory
      %HOMEPATH% The path to the user's home directory as defined in UMD/AD (excluding drive):
      \Users\<USERNAME> on Windows Vista & 2008
      \Documents and Settings\Guest on Windows XP
      %OS% Windows_NT (even on Windows Vista & XP machines
      The operating system the user is running
      %USERDOMAIN% The name of the domain that contains the user's account. On a stand-alone machine, the same as the machine name.
      %USERNAME% The user's name
      %USERPROFILE% C:\Users\<USERNAME> — The user's root folder
      %USERPROFILE%\Desktop The user's desktop folder

      tool If you have the permissions, invoke, then open my DOS batch file 1envvars.bat which lists the values of these variables on your computer

      Reminder Windows resolves commands typed in the start/run box first from files in %SYSTEMDRIVE%, then files in %SYSTEMROOT%. This is regardless of the systemdrive (such as E:) being later in the path. This means that a rogue file can be invoked instead of a good file (such as cmd.exe) if it's in the %SYSTEMDRIVE%.

      Below are dynamic environment variables:

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. User Environment Variables Added by Applications

      User environment variables are stored in Windows Registry HKEY_CURRENT_USER\Environment

      Within a command batch file, to list Oracle Environment Variablesanother page on this site

        echo ORACLE_SID = %ORACLE_SID%
        echo ORACLE_HOME = %ORACLE_HOME%
        echo ORA_NLS = %ORA_NLS%
        
        echo.
        echo PATH = %PATH%
        
        echo.
        echo Machine Name to messenger service:
        net name
        

      Novell adds these environment variables during installation.

      Variable
      %USER%
      %NWUSERNAME%
      %NWLANGUAGE%

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Creating Variables on Windows

      Environment Variables can be created and changed using several mechanisms:

      1. By Windows automatically upon boot-up.

      2. By application programs using Windows OS API functions. This is commonly done by application installation programs.

      3. Manually using GUI in System Properties, Advanced tab, Environment Variable button. Get to this one of two ways: System Properties tabs

          a). right-click My Computer icon, select Properties,
          b). click Start > Control Panel > System icon

        Click the Advanced tab, New for a new variable or Edit for an existing variable listed.

        System Variable Input dialog

        reminder System variables are available to all users.

      4. Manually using commands typed into the DOS Command Window obtained one of two ways:
          a). click Programs | Accessories | Command Prompt
          b). click Run..., type cmd and press Enter.

        To see all variables, type:

          SET

          Windows uses a tilde ~ character to substitute for parts of file and folder names longer than 8 characters.

        To use the SET command to define a single variable:

          SET CLASSPATH=.;path1

        The dot specifies the current directory. The semicolon separates two folders. If the variable was already established, this will replace its value.

        To add a value in front of the existing value, refer to itself:

          SET CLASSPATH=path1;%CLASSPATH%

        caution Variables created with SET are only valid for the current session and will not be available after the command window is closed or the computer reboots.

      5. By commands executed from within an AUTOEXEC.BAT file or host script fileanother page on this site

        tool run this sample logon.bat file. (Click Open when prompted. Your firewall may -- rightfully -- block this.)

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen MS PATH

      Forest Path in Winter at the New York Botanical Garden Forest
      Reminder The operating system looks for executables down the list of folders listed in the PATH User variable. The operating system uses the first occurance it finds. So watch out for multiple versions of the same program. For example, the Oracle install automatically adds:

      Program Files\Oracle\JRE\1.1.7\Bin;

      To enable command line invocation of compiler program csc.exe of the Microsoft .NET Framework, add this to the end of your PATH environment variable.

      1. Click
      2. Right-click on "My Computer" to select Properties.
      3. Click the "Advanced" tab.
      4. Click the "Environment Variable" button.
      5. Scroll down the "System variables" list to the "Path" variable.
      6. Double click on "Path"
      7. Press the "End" key
      8. Type (beginning with a semicolon separator) ;%systemroot%Microsoft.NET\Framework\v1.1.4322
      9. Click "OK"
      10. Click "OK" to close the System Properties window.

      Verify the change:

      1. Click
      2. Click Run... for a Run window.
      3. Type "cmd" in the Open: field.
      4. Click "OK"
      5. Type a command such as "csc"
      6. You are unsuccessful if you get back a response such as

        'csc' is not recognized as an internal or external command,
        operable program or batch file.

      To spare its users, most commercial applications provide an installer which does this automatically. For example, Microsoft .NET Framework SDK has a vcvars32.bat file to update paths on Windows 9x machines.

      Reminder Avoid spaces in path names (for backward compatibility and to avoid trouble) by using the 8 character equivalents.
      For example, to reach

        C:\Program Files\Mercury Interactive\Mercury LoadRunner\bin
      specify
        C:\PROGRA~1\MERCUR~1\MERCUR~1\bin

      The sequence in my PATH:

      1. C:\PROGRA~1\Java\jdk1.5.0_02\bin;
      2. C:\PROGRA~1\MERCUR~1\MERCUR~1\classes;
      3. %SystemRoot%\system32;
      4. %SystemRoot%;
      5. %SystemRoot%\System32\Wbem;
      6. %systemroot%\Microsoft.NET\Framework\v1.1.4322;
      7. C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;
      8. c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin;
      9. c:\program files\microsoft platform sdk for windows xp sp2\include


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. UNIX Environment Variables

      In UNIX/Linux systems, to list environment variables:

        env

      In UNIX/Linux systems, add a dollar sign ($) in front of each variable name in all caps:

        echo $LOGNAME user name used for login
        echo $USER user name (sudo)
        echo $UID user name Solaris
        echo $SHELL directory containing OS shell executables
        echo $PATH directories containing executables, searched to find applications when no absolute path is specified on the command line.
        echo $LD_LIBRARY_PATH path to system and user libraries
        echo $MANPATH directory containing manuals
        echo $HOME directory of user's home directory
        echo $TZ time zone, such as "US/Mountain"

      Reminder In UNIX systems, the colon (:). In Windows systems, the semi-colon (;) is used. So to list each path in a separate line:

        echo $PATH | tr ':' '\n'

      Solaris systems have additional ones, including:

        echo $BASH path to the shell on the file system.
        echo $HOSTNAME name of the current system.
        echo $PPID parent process ID
        echo $WINDOWMANAGER name of the X11 window manager
        echo $COLUMNS The column width for the terminal
        echo $DISPLAY The display variable used for X11 graphics.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Creating Variables on Linux

      To update an environment variable that lives until the next reboot:

        #export PATH=”/usr/local/XXX/bin:$PATH”
        #echo $PATH

      Notice that colons are used to separate path items.

      To create an environment variable that lives forever, update your .bash_profile file:

        XXXPATH=”/usr/local/XXX/bin”
        export XXXPATH

      For a list of environment settings (arguments) for a process with PID 23141 (on Solaris):

        pargs -ae 23141

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Java Environment Variables

      JDK versions 1.2 and 1.3 require variables Xrunmic_supp and Xbootclasspath %mic_class%

      Caution! The Java interpreter searches the PATH for a class by name and loads the first one it finds. So specify your own library and the most recent library first (especially if you use the same name as a class in a standard library).

      Performance tuning tip Also, for best performance, place the most-often used libraries at the front of the path. This applies to LIBPATH and LD_LIBRARY_PATH variables for most often used JNI libraries.

      webpage article Java 1.4 Documentation on Classpath notes that the preferred method for command-line tools such as java, javac, or javadoc is to NOT use environment variables but instead specify -classpath as part of the command invoking a Java program.

      Reminder The System environment variable CLASSPATH must be in upper case (not “classpath”). CLASSPATH is used to specify the full path and file name of every jar file used by java programs. Thus CLASSPATH could be quite long.


        C:\jdk1.3.1_01\src.jar;
        C:\jdk1.3.1_01\lib\dt.jar;
        C:\jdk1.3.1_01\lib\tools.jar;
        C:\jdk1.3.1_01\jre\lib\il8n.jar;
        C:\jdk1.3.1_01\jre\lib\jaws.jar;
        C:\jdk1.3.1_01\jre\lib\rt.jar;
        C:\jdk1.3.1_01\jre\demo\sound\JavaSound.jar;
        C:\jdk1.3.1_01\demo\jfc\SwingSet2\SwingSet2.jar;
        C:\jdk1.3.1_01\demo\jfc\SwingApplet\SwingApplet.jar;

      Sun's JDK adds:

        C:\jdk1.3.1_01\;
        C:\jdk1.3.1_01\Bin;
        C:\jdk1.3.1_01\Lib;

      Reminder A common mistake with CLASSPATH is to specify only folder paths and leave out jar file names. Semicolons should separate each jar file specification.

      On client machines, Microsoft's VM CLASSPATH is, by default:

        %windows%\Java\Classes\Classes.zip;

      This string is stored in environment variable CLASSPATH or Windows registry key

        HKLM\Software\Microsoft\Java VM\Classpath

      Windows 95/98 computers should limit CLASSPATH to less than 400 characters.

      Dick Baldwin notes in his tutorial that if you want the CLASSPATH to point to class files that belong to a package, you should specify a path name that includes the path to the directory one level above the directory having the name of your package.

      For example, suppose you want the Java interpreter to be able to find classes in the package mypackage. If the path to the mypackage directory is C:\java\MyClasses\mypackage, you would set the CLASSPATH variable as follows:

      set CLASSPATH=C:\java\MyClasses

      The purpose of the package directive is to identify a particular class (or group of classes contained in a single source file (compilation unit)) as belonging to a specific package.

      NOTE: Training connection also offers some great tutorials on Java programs, Dreamweaver training, and Flex software.

      In Linux: pCLASSPATH=/usr/local/java/jre/bin

      My CLASSPATH:

      1. C:\PROGRA~1\MERCUR~1\MERCUR~1\classes;
      2. C:\PROGRA~1\MERCUR~1\MERCUR~1\classes\srv;
      3. C:\PROGRA~1\Java\jdk1.5.0_02\lib\rt.jar

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Amazon EC2 File Paths

      Amazon EC2 command script users add these environment variables. For example, if EC2 files are located in folder C:\EC2:

      Variable Sample
      EC2_HOME C:\EC2 where files are located
      EC2_PRIVATE_KEY C:\EC2\pk.pem full path to file
      EC2_CERT C:\EC2\509cert.pem full path to file

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Windows Network Shares

      Changes to variables disappear after reboot.
      So change the variables in a shell script or Windows network share. This mapdir.bat is an example of allocating the X: drive.

      ...
      

      This assumes that the loopback IP address has not been changed in the hosts file.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Microsft T-SQL to Read Windows environment variables

      To read Windows environment variables using Microsoft SQL Server T-SQL code:

      -- Display all environment variables
      EXEC master..xp_cmdshell 'set'
      ------------
       
      -- Retrieve a single environment variable - Read environment variable
      DECLARE @EnvVar nvarchar(256)
      CREATE TABLE #Upload(EnvVar nvarchar(256))
      INSERT INTO #Upload
      EXEC xp_cmdshell 'echo %USERDOMAIN%'
      DELETE #Upload WHERE EnvVar is NULL OR EnvVar = ''
      SET @EnvVar = (SELECT EnvVar from #Upload)
      SELECT @EnvVar as [User Domain]
      /* User Domain ENTERPRISE */
      DROP TABLE #Upload
      

      Source: sqlusa.com

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Portions ©Copyright 1996-2011 Wilson Mar. All rights reserved. | Privacy Policy |

    Search


    How I may help

    Send a message with your email client program


    Your rating of this page:
    Low High




    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 



      Top of Page Go to top of page

    Thank you!