| language
Information, tips and tutorials for ZTree file manager
s_NT2KXP_variables
NT/2K/XP variables
System environment variables
Original source: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_o.mspxSystem environment variables are preset in the operating system and available to all Windows XP processes. Only users with administrative privileges can change system variables. These variables are most commonly used in logon scripts.
Most useful ones
| Variable | Description |
| %ALLUSERSPROFILE% | Returns the location of the All Users Profile. |
| %APPDATA% | Returns the location where applications store data by default. |
| %CD% | Returns the current directory string. |
| %SYSTEMDRIVE% | Returns the drive containing the Windows XP root directory (that is, the system root). |
| %SYSTEMROOT% | Returns the location of the Windows XP root directory. |
| %TEMP% and %TMP% | Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP. |
| %USERPROFILE% | Returns the location of the profile for the current user. |
More variables
| Variable | Description |
| %CMDCMDLINE% | Returns the exact command line used to start the current Cmd.exe. |
| %CMDEXTVERSION% | Returns the version number of the current Command Processor Extensions. |
| %COMPUTERNAME% | Returns the name of the computer. |
| %COMSPEC% | Returns the exact path to the command shell executable. |
| %DATE% | Returns the current date. Uses the same format as the date /t command. Generated by Cmd.exe. For more information about the date command, see Date |
| %ERRORLEVEL% | Returns the error code of the most recently used command. A non zero value usually indicates an error. |
| %HOMEDRIVE% | Returns which local workstation drive letter is connected to the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups. |
| %HOMESHARE% | Returns the network path to the user's shared home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups. |
| %HOMEPATH% | Returns the full path of the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups. |
| %LOGONSEVER% | Returns the name of the domain controller that validated the current logon session. |
| %NUMBER_OF_PROCESSORS% | Specifies the number of processors installed on the computer. |
| %OS% | Returns the operating system name. Windows 2000 displays the operating system as Windows_NT. |
| %PATH% | Specifies the search path for executable files. |
| %PATHEXT% | Returns a list of the file extensions that the operating system considers to be executable. |
| %PROCESSOR_ARCHITECTURE% | Returns the chip architecture of the processor. Values: x86, IA64. |
| %PROCESSOR_IDENTFIER% | Returns a description of the processor. |
| %PROCESSOR_LEVEL% | Returns the model number of the processor installed on the computer. |
| %PROCESSOR_REVISION% | Returns the revision number of the processor. |
| %PROMPT% | Returns the command prompt settings for the current interpreter. Generated by Cmd.exe. |
| %RANDOM% | Returns a random decimal number between 0 and 32767. Generated by Cmd.exe. |
| %TIME% | Returns the current time. Uses the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time |
| %USERDOMAIN% | Returns the name of the domain that contains the user's account. |
| %USERNAME% | Returns the name of the user who is currently logged on. |
| %WINDIR% | Returns the location of the operating system directory |
General variables
Excerpt from : http://labmice.techtarget.com/articles/batchcmds.htmA variable is a replaceable parameter. The parameters %0 and %1 to %9 can be placed anywhere within a batch file. When the batch file is run, %0 is replaced by the name of the batch file, and the argument variables %1 to %9 are replaced by the corresponding parameters entered on the command line.
For example, to copy the contents of one folder to another, you would add the following statement in a batch file named mybatch.bat :
xcopy %1\*.* %2
When you run the file, you would type the following:
mybatch.bat C:\afolder D:\bfolder
The effect is the same as if you had written xcopy C:\afolder \*.* D:\bfolder in the batch file.
The % parameter expands the batch script argument variables (%0, %1, ..., %9) as follows:
%* in a batch script is a wildcard reference to all the arguments. For individual argument variables, the expansion options are explained in the following tables.
| Variable | Description |
| %~1 | expands %1 and removes any surrounding quotes (") |
| %~f1 | expands %1 to a fully qualified path name |
| %~d1 | expands %1 to a drive letter |
| %~p1 | expands %1 to a path |
| %~n1 | expands %1 to a file name |
| %~x1 | expands %1 to a file extension |
| %~s1 | expanded path contains short names only |
| %~a1 | expands %1 to file attributes |
| %~t1 | expands %1 to date/time of file |
| %~z1 | expands %1 to size of file |
| %~$PATH:1 | searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string. |
The modifiers can be combined to get compound results:
| Variable | Description |
| %~dp1 | expands %1 to a drive letter and path |
| %~nx1 | expands %1 to a file name and extension |
| %~dp$PATH:1 | searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found |
| %~ftza1 | expands %1 to a dir-like output line |
In the above examples %1 and PATH can be replaced by other valid values. The %~ syntax must be terminated by a valid argument number. The %~ modifiers may not be used with %*.
Character substitution throught temporary variables
Temporary environment variables can be used to hold temporary information, but under NT/2K/XP, they can also be used to modify text strings. The command is:SET variable=%variable:[character to search]:[character to replace]%
For example:
SET DUMMY=This is, a stupid test
SET DUMMY=%DUMMY:,=%
SET DUMMY=%DUMMY:stupid=nice%
echo %DUMMY%
Result: This is a nice testIt is also possible to extract or delete part of an environment variable:
SET variable=%variable:~[starting point],[length]%
For example:
SET DUMMY=This is a nice test
SET DUMMY=%DUMMY:~10,5%
echo %DUMMY%
Result: niceTo learn more about this feature, type SET /? at command prompt to display help.
Contributors to this page: laurent
.
Page last modified on Thursday 22 of February, 2007 22:55:07 EST by laurent.
