Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use windows variables

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces you how to use windows variables, the content is very detailed, interested friends can refer to reference, I hope to help you.

windows batch set command

[Setting variables]

Format: set variable name = variable value

Details: Set variable referenced by % variable name %

[Cancel variable]

Format: set variable name =

Details: Canceled variable % Variable name % will be empty if referenced

[Display variables]

Format: set variable name

Detail: Shows the values of all variables starting with the variable name

[List all available variables]

Format: set

[Calculator]

Format: set /a expression

Example: set /a 1+2*3 Output 7

! Attention!

set cannot be used in compound statements such as if 1==1 set a=2 or for %%i in (a) do set a=2

predefined variables

Here are some variables that have been defined at the bottom and can be used directly: they do not appear in the variable list displayed by SET

%CD% -extends to the current directory string.

%DATE% -extends to the current date in the same format as DATE command.

%TIME% -extends to the current time in the same format as the TIME command.

%RANDOM% -extends to any decimal number between 0 and 32767.

%ERRORLEVEL% -expands to the current ERRORLEVEL value.

%CMDEXTVERSION% -extends to the current command processor extension version number.

%CMDCMDLINE% -extends to the original command line where the command processor is invoked.

The full pathname for %0 bat is like 'C:\Windows\system32\xxx.bat'

%1 bat Parameter 1 and so on %2 Parameter 2...

%path% -Current environment variable. A semi-colon separated list of paths that may contain spaces, end with '\', or be enclosed in double quotes.

expansion variables

@ Variable associated with %i (bat parameter or %i of for loop)

Suppose the file is C:\Documents and Settings\jinsun\Desktop\ParseSinglePkgs.bat

%0 C:\Documents and Settings\jinsun\Desktop\ParseSinglePkgs.bat

%~dp0 C:\Documents and Settings\jinsun\Desktop\

%cd% C:\Documents and Settings\jinsun\Desktop

%~nx0 ParseSinglePkgs.bat

%~n0 ParseSinglePkgs

%~x0 .bat

@ Variables associated with %VAR%

%VAR: str1 =str2% will replace str1 in VAR with str2(str2 can be deleted if it is empty,str1 can be preceded by *, variable %ABC:*B=% is C)

%VAR:~0,-2% extracts all characters of the VAR variable except the last two

%VAR:~-2% will extract the last two VAR variables

System variables:

Their values are assigned automatically by the system according to predefined conditions, and we just need to call them

%ALLUSERSPROFILE%(alluserprofile) Locally returns the location of the All Users profile. C:Documents and SettingsAll Users

%APPDATA% (appdata) Local Returns the location where the application stores data by default. C:Documents and SettingsAdministratorApplication Data

%CD% (cd) locally returns the current directory string. C:Documents and SettingsAdministrator Desktop

%CMDCMDLINE% (cmdline) Returns the exact command line used to launch the current Cmd.exe locally. cmd /c ""C:Documents and SettingsAdministrator table a.bat " "

%CMDEXTVERSION%(cmdextversion) The system returned the version number of the current Command Processor Extensions. 2

%COMPUTERNAME% (computername) The system returns the name of the computer. xxxx

%COMSPEC% (comspec) The system returns the exact path of the command line interpreter executable. C:WINDOWSsystem32cmd.exe

%DATE% The system returns the current date. Use the same format as the date /t command. Generated by Cmd.exe. For more information about the date command, see Date.

%ERRORLEVEL% (errorlevel) The system returned the error code for the previous command. Non-zero values are usually used to indicate errors.

%HOMEDRIVE% (homedrive) The system returns the local workstation drive letter connected to the user's home directory. Set based on home directory values. User home directories are those specified in Local Users and Groups. C:

%HOMEPATH% (homepath) The system returns the full path to the user's home directory. Set based on home directory values. User home directories are those specified in Local Users and Groups. Documents and SettingsAdministrator

%HOMESHARE% (homeshare) The system returns the network path to the user's shared home directory. Set based on home directory values. The user home directory is specified in Local Users and Groups.

%LOGONSERVER% (logonserver) locally returns the name of the domain controller verifying the current login session\ xxxx

%NUMBER_OF_PROCESSORS% (number_of_processors) The system specifies the number of processors installed on the computer.

%OS% (os) System returns the operating system name. Windows 2000 displays its operating system as Windows_NT. Windows_NT

%PATH% (path) The system specifies the search path for executable files. C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:Program FilesVc++ToolsWinNT;C:Program FilesVc++MSDev98Bin;C:Program FilesVc++Tools;C:Program FilesVC98in

%PATHEXT% (pathext) The system returns a list of file extensions that the operating system considers executable. .COM .EXE .BAT .CMD .VBS .VBE .JS .JSE .WSF .WSH

%PROCESSOR_ARCHITECTURE% (processor_architecture) The system returns the chip architecture of the processor. Value: x86 or IA64 based on Itanium x86

%PROCESSOR_IDENTIFIER % (processor_identifier) The system returned a processor description.

%PROCESSOR_LEVEL% (processor_level) The system returns the model number of the processor installed on the computer. 15

%PROCESSOR_REVISION% (processor_revision) The system returns the version number of the processor. 4f02

%PROMPT% (prompt) locally returns the command prompt settings for the current interpreter. Generated by Cmd.exe.$ P$G

%RANDOM% (random) The system returns any decimal number between 0 and 32767. Generated by Cmd.exe. 30580

%SYSTEMDRIVE% (systemdrive) The system returns a drive that contains the Windows server operating system root directory (that is, the system root directory). C:

%SYSTEMROOT% (systemroot) The system returned the location of the Windows server operating system root directory. C:WINDOWS

%TEMP%(temp) C:DOCUME~1ADMINI~1LOCALS~1Temp and %TMP% (tmp) C:DOCUME~1ADMINI~1LOCALS~1Temp The system and user returns the default temp directory used by applications available to the currently logged in user. Some applications require TEMP, while others require TMP.

%TIME% The system returns the current time. Use the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time.

%USERDOMAIN%(userdomain) locally returns the name of the domain containing the user account. xxxx

%USERNAME% (username) Locally returns the name of the currently logged in user. Administrator

%USERPROFILE% (userprofile) Locally returns the location of the profile for the current user. C:Documents and SettingsAdministrator

%WINDIR%(windir) The system returns the location of the operating system directory. C:WINDOWS

About how to use windows variables to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report