December 6, 2008

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 cialis generic vs brand 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, 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

November 12, 2008

Windows Explorer

Windows Explorer

I have one more Q&A for you today. I hope you don't mind too much!

Q:
What exactly is Windows Explorer? I've heard the term mentioned several times in your tips, but I've never gotten a good grasp as to what it is. Please explain!

A:
You know what? This question came at the most perfect possible time. It was brought to my attention yesterday by our tech support guy, Gary, that we don't really have any good tips in our archives for the Windows Explorer application. After he told me that, I went and checked them out and he was absolutely right. It seems like all the tips we have already written just sort of skate around the actual concept of what Windows Explorer is. What a shame!

So, I thought it would be in everyone's best interest to clear up all the details. If you've been wondering for awhile (like the person who asked this question) what Windows Explorer really is and why it's on your computer, you better listen up, because I'm going to fill you in today. Let's get started, shall we?!

To begin with a basic definition, Windows Explorer is a type of file manager. It's an application that comes with every Windows operating system that provides you with detailed information about your computer's files, folders and drives. It covers everything from your Documents and Settings to your My Documents files to your C: drive and so on and so forth. No matter what type of files you have on your computer or where you keep them, Windows Explorer can manage them.

There are several things you can do with Windows Explorer. For example, you're able to see how your files, etc. are organized in your computer system. It even helps you to do those little tasks of finding, saving, cialis for daily use copying, moving, deleting and even renaming your data. You know, all of those processes you go through probably every day with your files. Windows Explorer is known for being one of the best tools available for file managing and it's all free. Wow, who knew?!

Now, there are actually several different ways that will get you to the Windows Explorer application. The easiest way is to right click either the Start button or the My Computer icon on your desktop and choose Explore. On the other hand, if you like to use keyboard shortcuts, you can get there by hitting the Windows key and the letter E (Win + E) at the same time. Those two are probably the quickest access points, but other ways include going through your programs. In Windows XP, just go to Start, All Programs, Accessories, Windows Explorer. Either way you go, the Windows Explorer window will open right up for you on your computer screen.

Okay, there's one more thing I want to tell you and then I'll be able to rest easy knowing you all now have a full knowledge of Windows Explorer. When you go to open Windows Explorer, it will bring up a file directory for you. But what if that's not the one you want to work in? For example, Windows Explorer may bring up your Documents and Settings when you want to start out in your C: drive. Well, when that happens, you can easily change where Windows Explorer opens. Here's an example of how you can do that.

Right click on your desktop and go to New, Shortcut. In the command box, you'll have to type in a new directory. So, if you want Windows Explorer to open to your C: drive, enter this command line in: explorer /n,/e,/root,,/select,C:\. Make sure you keep all the spaces in as well. Click Next and then Finish. A new icon will come up on your desktop and when you double click that, Windows Explorer will open to your C: drive. If you want to open Windows Explorer from any of the ways we talked about above, you can do that as well, but either way, your C: drive will be the one that pops up.

For more examples on changing your directory routes, you can read here. Once you have everything set the way you want it, you'll be able to use Windows Explorer for all your file managing needs. It's so easy to use and it doesn't get any more convenient than being right there on your computer every time you boot it up. I hope you now have a better understanding as to what Windows Explorer really is and now, you can finally get some good use out of it!

Permalink • Print • Comment

November 9, 2008

How do I… stop Windows XP from nagging me about updates?

  • Date: September 17th, 2008
  • Author: Mark Kaelin

Microsoft’s Patch Tuesdays (the second Tuesday of every month) are an important part of every user’s regular Windows operating system maintenance. In fact, regular fixes, patches, and updates should be part of every user’s regular routine, no matter which operating system they use.

But sometimes Windows XP gets stuck in update mode. It will continue to show the flashing yellow shield in the System Tray suggesting you need to download and install important security patches. Windows may even display a chat bubble reminding you there is a system patch available. This may appear even after you have already applied all the patches — Windows just doesn’t recognize its current status.

Or, as in the case of TechRepublic member Riggy001, Windows may be telling you that SP3 is available, even though you have decided you don’t want to apply it right now or in the near future. This is the dilemma Riggy001 described in a TechRepublic Discussion Thread. To relieve this annoyance, Riggy001 called Microsoft support and finagled a procedure to reset the Windows update management system.

This cialis en francais blog post is also available in PDF format in a TechRepublic download.

Resetting Windows

  1. Click Start | Control Panel and then double-click Administrative Tools.
  2. Click on Services to open the dialog box (Figure A).

Figure A

Services dialog box
  1. From the list of services, right-click and then click Stop for the following services:
  • Automatic Updates
  • Background Intelligent Transfer Service
  • Cryptographic Services
  1. Next click Start | My Computer.
  2. Double-click the drive where XP is installed, usually C:\.
  3. Double-click Windows.
  4. Right-click on the file folder SoftwareDistribution and rename it SoftwareDistribution.old.
  5. Next double-click on the System32 file folder.
  6. Right-click on the folder Catroot2 and rename it Catroot2.old.
  7. Right-click on the folder SoftwareDistribution and rename it SoftwareDistribution.old.
  8. Close C:\Windows\System32 explorer window.
  9. Now, go back to the Services folder, right-click and then start the following services:
  • Automatic Updates
  • Background Intelligent Transfer Service (unless it was originally set to manual and you never had to stop the service in the beginning)
  • Cryptographic Services
  1. Close the Services Window and go to the Administrative Tools window (which should still be open).
  2. Click the Back Button on your toolbar to get back to the Control Panel.
  3. Double-click Automatic Updates (Figure B).

Figure B

Automatic Updates
  1. Select “Notify Me but Don’t Automatically Download or Install Them” radio button and then click the OK button.
  2. Close the Control Panel and resume computing.

One annoyance gone

This procedure forces Windows to reset the files that track what updates you have installed. This means that the automatic update will stop nagging you to update even though you already have. For Riggy001, this procedure means Windows will stop trying to download and install SP3.

One word of warning though, in general Windows updates are important not only for your security and peace of mind but also for the security of everyone else. I highly recommend that you apply the patches as soon as you can. Our Windows Patch Tuesday feature will keep you informed of just what each patch contains.

Permalink • Print • Comment

How do I… create a Suspend mode shortcut in Windows XP?

  • Date: August 20th, 2008
  • Author: Greg Shultz

On the Advanced tab of the Power Options Properties dialog box, Microsoft Windows XP provides you with several built-in shortcuts for putting your computer in Suspend mode — either Standby or Hibernation. These shortcuts allow you to reconfigure the operation performed when pressing either the Power or Sleep buttons. (If you’ve enabled the Hibernation feature from the Power Options Properties dialog box, using these shortcuts will put your computer into Hibernation mode. If you haven’t, using these shortcuts will put your computer into Standby mode.)

Figure A

Power Options dialog box — Advanced tab

This blog post is also available in PDF format in a TechRepublic download.

However, if you wish to expand your alternatives, you can create a standard shortcut that will put your computer in Suspend mode. You can the put the shortcut on your desktop or place it on the Quick Launch bar, where you can easily put your computer in a suspended state with a click of your mouse.

Here’s cialis ejaculation how:

  1. Right-click the desktop and select New | Shortcut.
  2. When the Create Shortcut wizard’s location text box appears, type:
    rundll32.exe PowrProf.dll, SetSuspendState
  3. Give the shortcut a name like Suspend Now!
Permalink • Print • Comment

How do I… turn off the Caps Lock key?

  • Date: September 9th, 2008
  • Author: Mark Kaelin

This blog post is also available in PDF format as a cialis dosages target=”_blank”>TechRepublic download.

Sometimes, depending on the manufacturer and on the particular layout, your keyboard can be a great source of frustration. For TechRepublic reader Frank Reeves, the Caps Lock key is the one that drives him crazy. After seeing the TechRepublic How do I… about how to disable the Insert key in Word, he asked for information on how to similarly disable the Caps Lock key.

There are several ways to accomplish this task. One way is to discover the scan code for the Caps Lock key and for the key you want to map it to and then edit the Windows registry. The folks at Annoyances.org explain this method. However, their explanation is more complicated than it needs to be, and there are easier and safer ways to accomplish the same thing.

Third-party keyboard layout and mapping tools are available that will allow you to change the behavior of the Caps Lock key, but many of these really boil down to a .reg file, which edits the Windows registry for you. In general, these .reg files are fine and come from people and organizations just trying to help make your life easier, but it still involves a stranger editing your Windows registry files. That makes me uncomfortable.

The best way to remap the Caps Lock key or any key on your keyboard is with a free utility from Microsoft called remapkey.exe. This little utility is available in the Windows Server 2003 Resource Kit Tools. It is one of many utilities included in the kit and works with Windows 2000, Windows XP, Windows Server 2003, and Windows Vista. This TechRepublic How do I… shows you how to use the remapkey.exe utility to remap the Caps Lock key.

Remapping

Once you download and run the Windows Server 2003 Resource Kit Tools file, you will have a long laundry list of utilities located in a single directory. I used the default location (Figure A):

  

  

Figure A

Tools

When you start the remapkey utility, it presents a screen displaying two keyboards, as shown in Figure B.

Figure B

Remapkey utility

The top keyboard is the standard base keyboard layout. To remap the Caps Lock key, in the top keyboard, click on the key you would like the Caps Lock to be remapped to, drag it to the bottom keyboard, and drop it on the Caps Lock key there. In my example, I am remapping the Caps Lock key to the left Shift key. (Note the red key in Figure C.)

Figure C

Caps Lock is now left Shift.

When you are satisfied with your remapping choices, click the Save And Exit icon to implement the change (Figure D). A reboot of the operating system will be required for the change to take effect.

Figure D

Save your settings and exit.

As you can see in Figure E, the remapkey utility is writing to the Windows registry, just like the methods mentioned earlier were going to do, but this gives you more control over that delicate editing process.

Figure E

Remapkey writes to the Windows registry.

Note: For Windows Vista, you will have to run the remapkey utility in administrator mode.

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