共用方式為


Logon Scripts Environment variables

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

Environment variables

When managing multiple user and group accounts, you may need to make the same change to many accounts. You can use environment variables to replace static names or labels with a dynamic variable. The dynamic variable is replaced by the appropriate environment data when called.

Changing the system environment variables

Servers running Windows Server 2003 require certain information to find programs, to allocate memory space for some programs to run, and to control various programs. This information, called the system and user environment variables, can be viewed using the System Properties in Control Panel on the Advanced tab. These environment variables are similar to those that can be set in the MS-DOS operating system, such as PATH and TEMP.

The system environment variables are the same regardless who is logged on to the computer. If you are logged on as a member of the Administrators group, you can add new variables or change the values.

The user environment variables can be different for each user of a particular computer. They include any environment variables you want to define, or variables defined by your applications, such as the path where application files are located.

After you change any environment variables, the new values are saved in the registry, making them automatically available the next time you start your computer.

If any conflict exists between environment variables, variables are set in this way:

  • System environment variables are set first.

  • Variables defined in the Autoexec.bat file (except for Path variables) are set next, and override system variables.

  • User environment variables defined in System Properties are set next, and override both the system and Autoexec.bat variables.

  • Path variables defined in the Autoexec.bat file are set last.

Path settings, unlike other environment variables, are cumulative. The full path (what you see when you type path at the command prompt) is created by appending the path contained in Autoexec.bat to the paths defined in System Properties in Control Panel.

Using system environment variables in user profile paths, home directory paths, and logon scripts

Any system environment variable on a Windows-based client computer can be used in a user account profile path, logon script path, home directory path, and within a logon script itself. For a list of system environment variables, see Command shell overview

This feature helps to ensure that logon scripts and user profiles run most efficiently on domains that span wide area network (WAN) links, especially if users work at more than one site.

For example, suppose you have two physical sites, one located in Paris, and the other located in London. On every computer running an operating system in the Windows Server 2003 family at the London site, you can set the servername system environment variable to the computer name of a backup domain controller in London. On the computers in Paris, you can set servername in a similar way, using the computer name of the backup domain controller in Paris. For domain user accounts, you can use %servername% in the logon script paths (for example, \\%servername%\scripts). When a user logs on, the logon script is always loaded from a server at the local site.

For more information, see the Resource Kit.

For more information about constructing scripts, see System Administration Scripting Guide at the Microsoft Windows Resource Kits Web site.