System built in variables of windows batch cmd batch command

Reference: Variables often used in batch processing and batch processing > detailed introduction to nul

 

Most of the environment variables can be displayed in powershell with the following command

ls env:

 

Absolute path refers to the path to call the absolute program location, for example:

start C:\Windows\test.exe

Relative path refers to the file. After changing the path, it will be called according to the path location of the variable, for example:

start %WINDIR%\test.exe

If the system is installed on disk D and the absolute path is used, the calling program may not be found in the system deployment and installation. At this time, the relative path is needed to call, and the variable parameters are used

Their values are actively assigned by the system according to the pre-defined conditions, that is, these variable systems have defined values for them. We don't need to assign values to them, we just need to call them! I'll list them all!

echo %ALLUSERSPROFILE% ::return"All users"Address of the configuration file. Example: C:\Documents and Settings\All Users(win7 Start to become C:\ProgramData)

2.%APPDATA%

echo %APPDATA% ::Local returns the status of data stored by the program by default. Example: C:\Documents and Settings\Administrator\Application Data(win7 Start to become C:\Users\%username%\AppData\Roaming)

3.%CD%

echo %CD% ::Returns the current directory string locally. Example: E:\hall\ebook\Small script

4.%CMDCMDLINE%

echo %CMDCMDLINE% ::Local return is used to start the current Cmd.exe The correct command line. Example: cmd /c ""E:\hall\ebook\Small script\2.bat" "
be careful: This one works ls env: No output

5.%CMDEXTVERSION%

echo %CMDEXTVERSION% ::The system returns the current"Expand command handler"Version number of the. Example: 2

be careful: This one works ls env: No output

6.%COMPUTERNAME%

echo %COMPUTERNAME% ::The system returns the name of the computer. Example: HP05281125

7.%COMSPEC%

echo %COMSPEC% ::The system returns the correct path of the executable program of the command line interpreter. Example: C:\WINDOWS\system32\cmd.exe

8.%DATE%

echo %DATE% ::The system returns the current date. Use and date /t A pattern of similar orders. from Cmd.exe Generate. of date For more information about the command, see Date. Example: 2011-01-12 Wednesday

9.%ERRORLEVEL%

echo %ERRORLEVEL% ::The system returns the error code of the previous command. A non-zero value is usually used to represent the fault. Example: 9009

10.%HOMEDRIVE%

echo %HOMEDRIVE% ::The system returns the drive letter of the local workstation connected to the user's home directory. Set based on home directory value. User home directory is in"Local users and groups"Specified in. Example: C:

11.%HOMEPATH%

echo %HOMEPATH% ::The system returns the full path of the user's home directory. Set based on home directory value. User home directory is in"Local users and groups"Specified in. Example:\Documents and Settings\Administrator

12.%LOGONSERVER%

echo %LOGONSERVER% ::Returns the name of the domain controller that validates the current login session locally. Example: \\HP05281125

13.%NUMBER_OF_PROCESSORS%

echo %NUMBER_OF_PROCESSORS% ::The system specifies the number of processors installed on the computer. Example: 4

14.%OS%

echo %OS% ::The system returns the name of the operating system. Windows 2000 Display its operating system as Windows_NT. Example: Windows_NT

15.%PATH%

echo %PATH% ::The system specifies the search path for executable files. Example: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem

16.%PATHEXT%

echo %PATHEXT% ::The system returns a list of executable files whose names the operating system has expanded. Example:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

17.%PROCESSOR_ARCHITECTURE%

echo %PROCESSOR_ARCHITECTURE% ::The system returns the chip system configuration of the processor. Example: x86

18.%PROCESSOR_LEVEL%

echo %PROCESSOR_LEVEL% ::The system returns the model of the processor installed on the computer. Example: 6

19.%PROCESSOR_REVISION%

echo %PROCESSOR_REVISION% ::The system returns the version number of the processor. Example: 170 a

20.%PROMPT%

echo %PROMPT% ::Returns the command reminder setting of the current descriptor locally. from Cmd.exe born. Example: $P$G

21.%RANDOM%

echo %RANDOM% ::The system returns any decimal number between 0 and 32767. from Cmd.exe Generate. Example: 30848

22.%SYSTEMDRIVE%

echo %SYSTEMDRIVE% ::System returns include Windows server operating system The drive of the root directory (that is, the root directory of the system). Example: C:

23.%SYSTEMROOT%

echo %SYSTEMROOT% ::System return Windows server operating system The location of the root directory. C:\WINDOWS. Example: C:\WINDOWS

24.%TEMP%

echo %TEMP% ::The system and the user return the default temporary directory applied to the application available to the currently logged in user. Some applications require TEMP,Other applications require TMP. Example: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp

25.%TIME%

echo %TIME% ::The system returns the current time. Application and time /t A pattern of similar orders. from Cmd.exe born. of time For more information about the command, see Time. Example: 19:55:12.75

26.%USERDOMAIN%

echo %USERDOMAIN% ::Returns the name of the domain that includes the user account locally. Example: HP05281125

27.%USERNAME%

echo %USERNAME% ::Returns the name of the currently logged in user locally. Example: Administrator

28.%USERPROFILE%

echo %USERPROFILE% ::Returns the location of the current user's profile locally. Example: C:\Documents and Settings\Administrator(win7 Start, path in C:\Users\lower)

29.%WINDIR%

echo %WINDIR% ::The system returns the status of the operating system directory. Example: C:\WINDOWS

With so many system variables, how do we know what their values are?
Enter echo% windir%, windir variable name in CMD. It's not random! In this way, the value of a variable can be displayed!
For example, if we want to copy files to the startup directory of the current account, we can do this
copy d:\1.bat "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
%USERNAME% returns the name of the currently logged in user locally.  

Posted by kjelle392 on Fri, 20 May 2022 15:00:01 +0300