Networking Environment variables
The command shell makes several environment variables available to commands. Environment variables all begin and end with percent signs. You can use an environment variable anywhere in a command. For example,
C:\>echo %OS% running on a %PROCESSOR_IDENTIFIER%
displays a line such as this:
Windows_NT running on an x86 Family 15 Model 2 Stepping 8,
Interestingly, Windows NT, Windows 2000 Server, Windows Server 2003, and Windows Server 2008 all display "Windows_NT" for the operating system name.
If the environment variable represents a path, you may need to enclose it in quotation marks, like this:
This command displays the contents of the user's home directory. The quotation marks are required here because the environme>nt variable expands to a pathname that may include spaces, and the command shell requires that long filenames that include spaces must be enclosed in quotation marks.
Table-1 lists the environment variables that are available to you and your commands.
|The location of the All Users profile
|The path where applications store data by default
|The path to the current directory
|The command line that was used to start the command shell
|The version number of the command shell
|The computer's name
|The path to the command shell executable (cmd.exe)
|The current date in the format generated by the date /t command
|The error returned by the most recent command
|The drive letter of the user's home directory
|The path to the user's home directory
|The network path to the user's shared home directory
|The name of the domain controller the user logged on to
|The number of processors on the computer
|The name of the operating system
|The current search path
|A list of the extensions the operating system treats as executable files
|The chip architecture of the processor
|A description of the processor
|The revision level of the processor
|The current prompt string
|A random number between 1 and 32,767
|The drive containing the operating system
|The path to the operating system
|The path to a temporary folder for temporary files
|Same as %TEMP%
|The time in the format produced by the time /t command
|The name of the user's domain
|The user's account name
|The path to the user's profile
|The path to the operating system directory
A batch file is simply a text file that contains one or more commands. Batch files are given the extension .bat and can be run from a command prompt as if they were commands or programs. You can also run a batch file from the Start menu by choosing Start → Run, typing the name of the batch file, and clicking OK.
As a network administrator, you'll find plenty of uses for batch files. Most of them won't be very complicated. For example, here are some examples of very simple batch files:
- Used a one-line file to copy the entire contents of an important shared network drive to a user's computer every night at 10 p.m. The user had just purchased a new Dell computer with a 100GB drive, and the server had only a 20GB drive. The user wanted a quick-and-dirty backup solution that would complement the regular tape backups that ran every night.
- Used a pair of short batch files to stop and then restart Exchange server before and after nightly backups for backup software that didn't have an Exchange plug-in that could back up the mail store while it was open.
- If frequently need to work with several related folders at once, create a short batch file that opens Explorer windows for each of the folders. (You can open an Explorer window from a batch file simply by typing the path to the folder that you want to open as a command.) Then, place the batch file on my desktop so I can get to it quickly.
You can also use batch files to create logon scripts that are executed whenever a user logs on. Microsoft keeps trying to get users to use profiles instead of logon scripts, but many networks still use logon scripts.