Windows XP also includes a number of variables to help control and define the user environment. The %username% can be used in place of the currently logged on user, because it will be populated with that value automatically. This comes in handy if you were writing a logon script, and wanted to use the same script for multiple users. For example, the command net use g: \\server1\users\%username% could be used to map drive G: to a folder with the same name as the logged on user. This will save the time and effort associated with creating many individual scripts for different users.
Other useful user-related variables include %userprofile% (try issuing the command cd %userprofile% from the command line C:\> prompt), which was discussed earlier, and %userdomain%, which will return the name of the domain of which the current user is a member. For example, at the command line type echo %userdomain%, and the name of the domain (or computer) that validated the user’s logon request will be displayed.
While XP will open files with an EXE extension from the run command without the need to explicitly provide the extension, the same is not true for all other extensions. However, you can control this by adding those extensions to a variable named PATHEXT. This system variable controls which extensions are tried when not supplied. One of our personal favorites is adding the MSC extension, which allows administrative consoles like the Services tool (services.msc) to be quickly opened from the Run command.
Similarly, the PATH variable controls the directories in which XP will search for a file when an extension is not provided. By default, the PATH variable will search three different directories, including C:\WINDOWS, C:\WINDOWS\system32, and C:\WINDOWS\system32\WBEM when a directory is not specified. By adding additional paths to this attribute, you can control which directories will be searched for the filename when a path is not specified. See the steps below for an overview of changing the PATH and PATHEXT variables on an XP system.
Step 1: Click Start, select Control Panel, and then click System. Click the Advanced tab, and the then click the Environment Variables button at the bottom of the screen. This will open the Environment Variables window shown in the background of Step 2.
Step 2: In the System variables section, click Path, and then click Edit. Place a semicolon after an entry (second, for example), and then type the full path to any additional directories you want searched. Click OK. Follow the same steps to add additional file extensions to the PATHEXT variable (for example, .MSC). Reboot once complete.
Step 3: To check whether your new PATH or PATHEXT variables are functioning correctly, attempt to open a file in the new path and with the new extension from the Run command. For example, type services at the Run command, and click OK. In this case, the Service.msc console should open automatically.
Before getting into how variables are configured, it’s important to have some understanding of the elements that variables control. One great example is when using the Run command. You may have noticed that you can use the Run command by typing cmd and pressing OK, without specifying the EXE extension. The command prompt will open in the case for two reasons. First, EXE is one of the extensions automatically attempted when one is not provided, and the extensions used are defined by an environment variable.
The second reason that the command prompt will open is that an environment variable is also defined that outlines in which directory paths XP should search for the specified file. For example, the file notepad.exe is found in the WINDOWS\system32 folder, and this is one of the paths defined in an environment variable. If you were to create a new folder called C:\notepad and move the notepad.exe file to that location, XP would no longer be able to find this program from the Run command, unless you explicitly specified the path. With a little tweaking and tuning of environment variable settings, you can easily change the default behavior of XP to your preferences.
Windows XP supports two main types of environment variables – user variables, and system variables. User variables are applicable to the currently logged on user only, while system variables apply to all users of an XP system. Windows XP allows users to create or change their own user variables, but only an administrator can change system variables. In most situations, user variables will apply once a user logs off and back on, while changes to system variables require the system to be rebooted.
The main tool used to configure environment variables on an XP system is the System applet in Control Panel. From the Advanced tab, click the Environment Variables button. This opens the Environment Variables window. From this interface, environment variables can be added, edited, and deleted as necessary.
Since back in the days of DOS, Microsoft operating systems have used environment variables as a way to control the user and system environment. While originally defined in files like Autoexec.bat, the capabilities and functions of environment variables are a core element to any XP system, and can be used to manipulate or control the ways in which applications and users interact with the operating system. With an understanding of existing and custom variables, you can easily obtain a greater degree of control over how your XP system functions.
At the most basic level, a variable is a type of placeholder that can be used instead of a piece of constant information when interacting with XP. Environment variables are typically used from the command line, within scripts, and by system functions in order to return a requested piece of information. For example, if you wanted to quickly access the Documents and Settings folder associated with the user currently logged on, you could open the Run command, type %userprofile%, and click OK. When environment variables are accessed on a Windows XP system, they are enclosed within percentage sign characters (%).