July 6, 2008

Environment Variables in Windows XP

Environment Variables in Windows XP
Environment variables are specially named aliases or placeholders for certain basic system properties that are present for convenience in programming and in system administration. Although they are mostly of interest to technical people, some can be useful to the average PC user and these are discussed here.

Environment variables have long been used in computer operating systems and are present in Unix, DOS, and Windows The word "environment" used in the context here refers to various features of the computer system and certain basic system data. Here is one of Microsoft's definitions:

Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.

Values for some of these variables are established at login and these are sometimes called predefined variables. They include such parameters as the path and the name of the current user. A table of some of the more useful variables is given below. I have omitted some of the more technical ones. A more complete list is at this Microsoft reference. The variables are enclosed by percent signs when used in scripts or the command line, as is shown in the table. Although the variables are shown in upper case, they are not case-sensitive. More details are given about some of them in subsequent sections.

(To conform to much of the literature on environment variables, I will be using the term "directories" instead of "folders" in the discussion.)

Variable Typical value (May vary, depending on system)
%ALLUSERSPROFILE% C:\Documents and Settings\All Users
%APPDATA% C:\Documents and Settings\{username}\Application Data
%COMPUTERNAME% {computername}
%COMSPEC% C:\Windows\System32\cmd.exe
%HOMEDRIVE% C:
%HOMEPATH% \Documents and Settings\{username}
%PATH% C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem
%PATHEXT% .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH
%PROGRAMFILES% Directory containing program files, usually C:\Program Files
%PROMPT% Code for current command prompt format. Code is usually $P$G
%SYSTEMDRIVE% The drive containing the Windows XP root directory, usually C:
%SYSTEMROOT% The Windows XP root directory, usually C:\Windows
%TEMP% and %TMP% C:\DOCUME~1\{username}\LOCALS~1\Temp
%USERNAME% {username}
%USERPROFILE% C:\Documents and Settings\{username}
%WINDIR% C:\Windows

The so-called predefined variables are generally unchanged during a login session but there are also some dynamic variables whose value may change. Some of these are listed in the next table.

Variable Value
%DATE% Current date in the format determined by the Date command
%TIME% Current time in the format determined by the Time command
%CD% Current directory with its full path
%ERRORLEVEL% Number defining exit status of a previous command or program
%RANDOM% Random number between 0 and 32767

Environment variables are very convenient in scripts where certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.(Note that the presence of spaces in some names may necessitate the use of enclosing quotation marks around environment variables in scripts.) By having a placeholder, no prior knowledge is required of such details as the exact location of Windows or who is logged in. Some possibilities are explored in the following sections.

The PATH Environment Variable

The path to a file is basically its address on the computer. It tells programs how to find a file. It is the drive plus any directories and sub-directories where the file is located. The %PATH% environment variable specifies the command search path. Typically, this is a group of directories where executable files that are repeatedly used are to be found. Examples of the default values are listed in the first table above; in this case, they are the Windows directory and two of its important system sub-directories. To see what is in the PATH variable on a computer, open a command window and enter "echo %PATH%".

The PATH variable is not immutable and programs like Norton SystemWorks will stick themselves into PATH when they are installed. The PC user can also modify the contents using methods discussed further on. Adding directories to PATH can be very useful if you use scripts or the command line for system maintenance. For example, it can be convenient to put the directory where you keep backups into the PATH variable. It can also be useful to modify PATH if you put programs in a directory different from the usual one.

In the command line and in batch files, PATH can be modified by the command path = dir1;dir2;dir3 This command will create a PATH environment variable consisting of the three directories dir1, dir2, and dir3. Note that the directory names are separated by a semicolon in the command statement. (An alternate form omits the "equals" sign.) This command will replace any previous directories that were in the PATH variable. To add a directory "newdir" to the current path use the statement path = %PATH%;newdir

It is essential to remember that any changes that are made in a command window only endure until the window is closed. For permanent changes, use the method discussed in another section. It is also possible to use the command-line executable setx.exe that is contained in the Windows XP Service Pack 2 Support Tools.

Any file that is in a directory listed in the PATH variable can be found or opened by direct reference to the name of the file without having to specify the drive and directories where it is located. This is very handy in scripting and in other ways. For instance, the name of an executable file that is in a directory listed in the PATH variable can be entered into Start-Run to open certain applications (more on this subject here). An example is the executable file for the classic version of the game Solitaire that is generally in the system folder C:\Windows\System32\. The file is sol.exe and its full address with complete path is C:\Windows\System32\sol.exe. Normally this entire string would have to be used in order to reference the Solitaire game. Because its directory is listed in the PATH variable, however, it is sufficient to reference just the file name sol.exe. In fact, because of another environment variable PATHEXT discussed next, simply entering sol into Start-Run is sufficient to open the solitaire game.

The PATHEXT Variable

As is explained on other pages, file extensions tell Windows what it is supposed to do with a file. Certain file extensions indicate that the file is executable; that is, the file opens a program or does something. The %PATHEXT% environment variable contains executable file extensions that do not have to be specified for any file in a directory given in the %PATH% variable. The extension .EXE is the most common. Thus the filename sol.exe need only be entered as sol in a command line. If files have the same name but different extensions, the operating system searches in the following order of precedence: .EXE, .COM, .BAT, and .CMD.

Adding or Editing Environment Variables

Existing variables can be edited or deleted and new ones can be added in several ways. For temporary changes, the command " Set" can be used in scripts or in a command window. An example is shown below: set temp=C:\tempHere, the %TEMP% directory has been changed from the default value. Note that the there must be no spaces on either side of the "equals" sign. Changes made with "Set" disappear when the command window is closed, thus rendering this method fairly uninteresting for the average PC user. A more useful application of "Set" is to list the environment variables. Open a command window and enter "set" to see what the variables are on your system. Those who wish can consult this Microsoft article for more details about "Set".

A more permanent way to manage environment variables is provided in  the System Properties dialog box. Open Control Panel-Performance and Maintenance-System (or right-click on My Computer and choose "Properties"). In the box that opens, ordering propecia online click the "Advanced" tab to obtain the dialog box shown below. Next, click the button "Environment Variables".

The figure below shows the "Environment Variables" dialog box that opens next. It lists two kinds of variable- those that apply only to the current user and those that apply to the whole system. You can simply scroll down the lists to see what is on your system or you can edit the lists. Note that I have created a user variable %BACKUP% that gives the path to my one of my backup directories. That makes it easier for me to write a backup script since all I have to do is enter %BACKUP% whenever I want to refer to this directory. To create a new variable, use the "New" button. There are also buttons for editing and for deleting variables.

The box for adding a new user variable is shown below. Generally, this is likely to be a directory that you use frequently but can be any string of less than 8192 bytes. The maximum total size for all environment variables, including variable names and the "equals" sign, is 32767 characters.

 

The next figure shows a box for editing a variable; in this case it is the PATH variable. Be sure to remember to separate directory names with a semicolon. If you use programs in a particular directory a great deal, you may wish to add it to the path. The figure shows that the directory "G:\Program Files\Support Tools\" has been added. 

 

Using the add-on tool Setx.exe

It is not part of the standard Windows XP setup but a command-line tool called setx.exe is included in the Windows XP Service Pack 2 Support Tools. This tool extends the set command so that permanent changes in the environment variables can be made. For example, to add a folder C:\New Folder to the path, the command would be setx path "%PATH%;C:\New Folder"

Scripts for Listing Environment Variables

The "Set" command can be used in a command prompt together with a redirection to a text file to make a list of the current environment variables. The command might be set > C:\env_list.txt The file name "C:\env_list.txt" can be replaced by any of your choice.

Microsoft also has a VBScript that lists environment variables on this page.

Registry Keys for Environment Variables

For those who are experienced with editing the Registry, there is another way to make changes in environment variables. User environment variables are stored in the Registry in the key:
HKEY_CURRENT_USER\Environment
System variables are found in the key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Note that any environment variable that is in the form that needs to be expanded (for example, %PATH%) must be stored in the registry as a REG_EXPAND_SZ registry value. Editing the Registry is primarily for scripts used by systems administrators and is not recommended for the average PC user.

Setting Environment Variables in Autoexec.bat

The file autoexec.bat is a relic from DOS and older versions of Windows but may still be present in some systems. For the most part, Windows XP will ignore any autoexec.bat file but entries defining environment variables will be picked up. Although environment variables can be set in this way, there are probably better ways.

Environment variables in Vista

The same general considerations hold but there are differences in the details of environment variables for Vista. These are discussed at vistaonwindows.com.

Permalink • Print • Comment

Product Key Finder 1.0.0.422

online prescription propecia onclick=”return RBDL.downloadNow('http://software-files.download.com/sd/fCfa6YYhSPwgX7ySKAIPclVZ9giNMxqgkhM8p4FzX3wwe8F-vKALZlKM8-pMkfNRvGiJtz7A8f0nMSJh5NBNmzpnrrUlcjUo/software/10736781/10694022/3/CPP-ProductKeyFinder.exe?lop=btn&ptype=1720&ontid=2094&siteId=4&edId=3&spi=184d28d0bc511a07b183053ae4c33d08&pid=10736781&psid=10694022', 'http://dw.com.com/redir?edId=3&siteId=4&oId=3000-2094_4-10694022&ontId=2094_4&spi=184d28d0bc511a07b183053ae4c33d08&lop=btn&tag=tdw_dlicon&ltype=dl_dlnow&pid=10736781&mfgId=6285359&merId=6285359&destUrl=http%3A%2F%2Fwww.download.com%2F3001-2094_4-10736781.html%3Fspi%3D184d28d0bc511a07b183053ae4c33d08', '0')”> Download Now (290.7K) Tested spyware free
License:
Free
Editor's Rating:
4 star editors rating
Average User Rating:
3 star user rating (out of 12 votes) Rate it!
Downloads:
35,188
Requirements:
Windows 95/98/Me/NT/2000/XP/2003 Server/Vista
Limitations:
No limitations
Date Added:
October 15, 2007

Publisher's description of Product Key Finder

From Aporah:

A simple C++ windows application to retrieve and decrypt Microsoft Windows and other Product installation keys. Written to help me out at work to establish who was using what software. Sourcecode available on request. If you'd like additional key finding capabilities to be added, just drop me an e-mail.

Version 1.0.0.422 adds support for Office 2007 and Visual Fox Pro 9.

Editor's review of Product Key Finder

4 star editors rating

Product Key Finder is a single function utility that executes in a GUI, but displays a Command window result. You merely double-click it to display the 25 character Microsoft Windows Product Key.

The publisher gives a URL for those who want a product that displays more keys. There are freeware tools on the market that already perform this function, and include multiple product keys. If you need a tool that only displays the OS key, then Product Key Finder is for you. It's accurate and free. Otherwise, there are other utilities in this genre that cover numerous registered programs.

Permalink • Print • Comment

DriverMax 4.2

Download Now (2.89MB) Tested spyware free
License:
Free
Editor's Rating:
5 star editors rating
Average User Rating:
3 star user rating (out of 246 votes) Rate it!
Downloads:
335,570
Requirements:
Windows XP/2003 Server/Vista
Limitations:
No limitations
Date Added:
June 17, 2008

Publisher's description of DriverMax

DriverMax is a powerful utility which helps you download, backup and restore the drivers installed on your Windows Vista or Windows XP computer and check if newer versions are available. Download all drivers from one place in just a few steps. Or back them up so you will have all of them in a single place and will be able to reinstall them in a few minutes. This tool can save you a lot of time when reinstalling Windows, especially on older computers for which the original CDs containing the drivers have been lost. You no longer have to track down old driver installation CDs, insert one installation CD after another or spend hours searching for drivers on the Internet. DriverMax is also able to display a detailed report about all drivers (versions, release dates) installed on your system. Identify unknown devices in your computer and get Windows Vista rating information before you purchase new hardware.

Version 4.2 improves the driver download speed as well as the unknown hardware device identification.

">Download Now (2.89MB) Tested spyware free

License:
Free
Editor's Rating:
5 star editors rating

online pharmacy propecia

Average User Rating:
3 star user rating (out of 246 votes) Rate it!
Downloads:
335,570
Requirements:
Windows XP/2003 Server/Vista
Limitations:
No limitations
Date Added:
June 17, 2008

Publisher's description of DriverMax

DriverMax is a powerful utility which helps you download, backup and restore the drivers installed on your Windows Vista or Windows XP computer and check if newer versions are available. Download all drivers from one place in just a few steps. Or back them up so you will have all of them in a single place and will be able to reinstall them in a few minutes. This tool can save you a lot of time when reinstalling Windows, especially on older computers for which the original CDs containing the drivers have been lost. You no longer have to track down old driver installation CDs, insert one installation CD after another or spend hours searching for drivers on the Internet. DriverMax is also able to display a detailed report about all drivers (versions, release dates) installed on your system. Identify unknown devices in your computer and get Windows Vista rating information before you purchase new hardware.

Version 4.2 improves the driver download speed as well as the unknown hardware device identification.

Permalink • Print • Comment
Made with WordPress and an easy to use WordPress theme • Sky Gold skin by Denis de Bernardy