Variables in Windows  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Microsoft Windows
Written by Adi Bach   
Wednesday, 13 December 2006
Article Index
Variables in Windows  Hot
Modifying Varibles
Creating, Modifying, and Deleting Script Variables

{mos_sb_discuss:42}

A variable is a reference to a location in the computer’s memory where your scripts can store and retrieve data. There are two primary types of variables that you will work with in Windows shell scripts, environment variables, and script variables.



An environment variable is created and maintained by the operating system. Your scripts can access and use the values stored in environment variables. The other type of variable that you’ll use are script variables. A script variable is created during the execution of a script and then deleted when the script stops running.

The Windows shell provides the SET command as your primary means for displaying, modifying, and deleting variables. The SET command supports several different variations of syntax, as shown below.

            SET [ Variable=[ Value]]

            SET /A Expression

            SET /P Variable=[ MessagePrompt]

 

When used in its first form, the SET command displays, creates, modifies, and deletes variables. Variable specifies the name of the variable to be displayed, created, modified, or deleted. Value specifies an optional data assignment.

The second form of the SET command defines numeric variables. /A designates that the value stored in the variable is to be treated as a number and Expression specifies the value assigned to the variable.

The final format of the SET command allows you to interactively prompt the user to type input, which is then assigned to a variable. /P specifies that the SET command should prompt for user input. Variable defines the name of the variable to which the user’s input is assigned, and MessagePrompt is an optional text string that you can use to present the user with instructions on what you want him to enter. 

Accessing Environment Variables

Windows operating systems collect and store information about the computer and its users in a special database known as the Windows registry. The information stored in the registry is collected from a number of sources. Some of the registry’s information is made available to you in the form of environment variables.

Thereare two types of environment variables:
• User environment variables provide information specific to the individual users.
• System environment variables provide information specific to the computer and its execution environment.
 

Viewing Environment Variable

On Windows XP, a number of environment variables can be accessed from the System Properties dialog using the following procedure:
1. Click on Start, right-click on My Computer, and select Properties from the menu
that appears. The System Properties dialog appears.
2. Select the Advanced property sheet.
3. Click on the Environment Variables button located at the bottom on the dialog.

User variables associated with the currently logged-on user are displayed at the top of the dialog. In this example, two user environment variables are shown, both of which specify the location of different temporary folders.

System environment variables are displayed at the bottom of the dialog. You’ll usually find a number of different system environment variables listed here, including

• COMSPEC. Specifies the location of the Windows shell (e.g., CMD.EXE).
• OS. Identifies the currently running Windows operating system.
• PATH. Specifies the default search path.
• PATHEXT. Lists file extensions that represent executable programs.
• Prompt. Specifies the default command prompt format.
• TEMP. Specifies the location of a folder where the system may store temporary files.
• WINDIR. Identifies the folder where system files are located.



Last Updated ( Saturday, 07 July 2007 )
 
< Prev   Next >