Windows10 环境变量_环境变量与用户变量

2022-10-01 17:38:54 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。 Windows 10 环境变量 (用户变量与系统变量)

1. 环境变量 (environment variables)

环境变量 (environment variables) 是在操作系统中用来指定操作系统运行环境的一些参数。环境变量是在操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息。Windows 和 DOS 操作系统中的 path 环境变量,当要求系统运行一个程序而没有告诉它程序所在的完整路径时,系统除了在当前目录下面寻找此程序外,还应到 path 中指定的路径去找。用户通过设置环境变量,来更好的运行进程。

代码语言:javascript复制
Environment variables:环境变量
User variables:用户变量
System variables:系统变量

环境变量可分为用户变量与系统变量两类,在注册表中都有对应的项。

1.1 用户变量

  • 用户变量所在位置:HKEY_CURRENT_USEREnvironment

1.2 系统变量

  • 系统变量所在位置:HKEY_LOCAL_MACHINESYSTEMControlSet001ControlSession ManagerEnvironment

在原有变量的基础上添加英文状态下的分号,然后添加路径名。不要删除原先的系统变量,只要用分号隔开,然后添加路径名,最后也要加上分号。

1.3 echo %path%

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %path%
C:Program Files (x86)IntelIntel(R) Management Engine ComponentsiCLS;C:Program FilesIntelIntel(R) Management Engine ComponentsiCLS;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program FilesMicrosoft SQL Server0ToolsBinn;C:Program Files (x86)Windows Kits.1Windows Performance Toolkit;C:UserschengAppDataLocalMicrosoftWindowsApps;

C:Userscheng>
C:Userscheng>echo %PATH%
C:Program Files (x86)IntelIntel(R) Management Engine ComponentsiCLS;C:Program FilesIntelIntel(R) Management Engine ComponentsiCLS;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program FilesMicrosoft SQL Server0ToolsBinn;C:Program Files (x86)Windows Kits.1Windows Performance Toolkit;C:UserschengAppDataLocalMicrosoftWindowsApps;

C:Userscheng>

环境变量可以理解为系统的视线范围,配置进入了环境变量的可执行程序,就等于是进入了系统的视线范围。

  • 系统变量针对所有用户起作用,为了安全一般配置用户环境变量。
  • 用户变量只对当前用户起作用,不建议为了省事而配置系统环境变量。
  1. 环境变量不区分大小写,path / PATH / Path 表示指定可执行文件的搜索路径。
  2. echo %path% 用户变量会跟在系统变量的后面。
  3. 用户环境变量优先级高于系统环境变量。对于环境变量,系统会先检查用户变量,之后再检查系统变量。
  4. 添加路径以后,要保存,再重启 cmd,确保生效。
  5. Windows 系统在执行用户命令时,若用户未给出文件的绝对路径,则首先在当前目录下寻找相应的可执行文件。然后在用户变量的 path / PATH / Path 路径中查找,如果找不到,再到系统变量的 PATH 路径中查找。如果系统变量和用户变量的 path / PATH / Path 中同时包含相同的路径,则优先使用用户变量 path / PATH / Path 中的路径。

2. Setting the path and variables in Windows 10

  1. From the desktop, right-click the Computer icon and select Properties. If you don’t have a Computer icon on your desktop, click Start, right-click the Computer option in the Start menu, and select Properties.
  2. Click the Advanced System Settings link in the left column.
  3. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
  4. In the Environment Variables window, highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.

You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New and enter the variable name and variable value.

此电脑 -> 高级系统设置

环境变量

3. List of environment variables in Windows 10

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %COMMONPROGRAMFILES%
C:Program FilesCommon Files

C:Userscheng>
C:Userscheng>echo %COMMONPROGRAMFILES(x86)%
C:Program Files (x86)Common Files

C:Userscheng>
C:Userscheng>echo %COMSPEC%
C:Windowssystem32cmd.exe

C:Userscheng>
C:Userscheng>echo %HOMEDRIVE%
C:

C:Userscheng>
C:Userscheng>echo %HOMEPATH%
Userscheng

C:Userscheng>
C:Userscheng>echo %SYSTEMROOT%
C:Windows

C:Userscheng>echo %WINDIR%
C:Windows

C:Userscheng>
C:Userscheng>echo %TMP%
C:UserschengAppDataLocalTemp

C:Userscheng>
C:Userscheng>echo %TEMP%
C:UserschengAppDataLocalTemp

C:Userscheng>

%COMMONPROGRAMFILES%C:Program FilesCommon Files %COMMONPROGRAMFILES(x86)%C:Program Files (x86)Common Files %COMSPEC%C:WindowsSystem32cmd.exe %HOMEDRIVE%C: %HOMEPATH%C:Users<username> %SYSTEMROOT%C:Windows %WINDIR%C:Windows %TMP%C:Users<username>AppDataLocalTemp %TEMP%C:Users<username>AppDataLocalTemp

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %APPDATA%
C:UserschengAppDataRoaming

C:Userscheng>
C:Userscheng>echo %ALLUSERSPROFILE%
C:ProgramData

C:Userscheng>
C:Userscheng>echo �%
C:Userscheng

C:Userscheng>
C:Userscheng>echo %CMDEXTVERSION%
2

C:Userscheng>
C:Userscheng>echo �TE%
2020/05/04 周一

C:Userscheng>
C:Userscheng>echo %ERRORLEVEL%
0

C:Userscheng>
C:Userscheng>echo %LOCALAPPDATA%
C:UserschengAppDataLocal

C:Userscheng>
C:Userscheng>echo %LOGONSERVER%
\YONGQIANG

C:Userscheng>
C:Userscheng>echo %PATH%
C:Program Files (x86)IntelIntel(R) Management Engine ComponentsiCLS;C:Program FilesIntelIntel(R) Management Engine ComponentsiCLS;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program FilesMicrosoft SQL Server0ToolsBinn;C:Program Files (x86)Windows Kits.1Windows Performance Toolkit;C:UserschengAppDataLocalMicrosoftWindowsApps;C:Program FilesNVIDIA CorporationNVSMI;

C:Userscheng>

%APPDATA%C:Users<username>AppDataRoaming %ALLUSERSPROFILE%C:ProgramData �% – Typing in this command will give you the current directory you are working in. %CMDEXTVERSION% – This variable expands to the version of the command-line extensions. �TE% – This variable will give you the current date according to date format preferences. %ERRORLEVEL% – Determines the error level set by last executing command. %LOCALAPPDATA%C:Users<username>AppDataLocal %LOGONSERVER%\<domain_logon_server> %PATH%C:Windowssystem32;C:Windows;

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:Userscheng>
C:Userscheng>echo %PROGRAMDATA%
C:ProgramData

C:Userscheng>
C:Userscheng>echo %PROGRAMFILES%
C:Program Files

C:Userscheng>
C:Userscheng>echo %PROGRAMW6432%
C:Program Files

C:Userscheng>
C:Userscheng>echo %PROGRAMFILES(X86)%
C:Program Files (x86)

C:Userscheng>
C:Userscheng>echo %PROMPT%
$P$G

C:Userscheng>
C:Userscheng>echo %SYSTEMDRIVE%
C:

C:Userscheng>
C:Userscheng>echo %TIME%
12:34:57.39

C:Userscheng>
C:Userscheng>echo %USERNAME%
cheng

C:Userscheng>

%PATHEXT% – .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc %PROGRAMDATA% – C:ProgramData %PROGRAMFILES% – C:Program Files %PROGRAMW6432% – C:Program Files %PROGRAMFILES(X86)% – C:Program Files (x86) %PROMPT% – PG %SYSTEMDRIVE% – C: %TIME% – Similarly, it gives you current time according to the time format preferences. %USERNAME% – <username>

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %USERPROFILE%
C:Userscheng

C:Userscheng>
C:Userscheng>echo %USERDOMAIN%
YONGQIANG

C:Userscheng>
C:Userscheng>echo %USERDOMAIN_ROAMINGPROFILE%
YONGQIANG

C:Userscheng>
C:Userscheng>echo %PUBLIC%
C:UsersPublic

C:Userscheng>
C:Userscheng>echo %PSMODULEPATH%
C:Program FilesWindowsPowerShellModules;C:Windowssystem32WindowsPowerShellv1.0Modules

C:Userscheng>
C:Userscheng>echo %ONEDRIVE%
C:UserschengOneDrive

C:Userscheng>
C:Userscheng>echo %CMDCMDLINE%
"C:Windowssystem32cmd.exe"

C:Userscheng>
C:Userscheng>echo %COMPUTERNAME%
YONGQIANG

C:Userscheng>
C:Userscheng>echo %PROCESSOR_REVISION%
9e0a

C:Userscheng>

%USERPROFILE%C:Users<username> %USERDOMAIN% – Userdomain associated with current user. %USERDOMAIN_ROAMINGPROFILE% – Userdomain associated with roaming profile. %PUBLIC%C:UsersPublic %PSMODULEPATH%%SystemRoot%system32WindowsPowerShellv1.0Modules %ONEDRIVE%C:Users<username>OneDrive %CMDCMDLINE% – Outputs command line used to launch the current Command Prompt session. %COMPUTERNAME% -Outputs the system name. %PROCESSOR_REVISION% – Outputs processor revision.

代码语言:javascript复制
Microsoft Windows [版本 10.0.17763.1158]
(c) 2018 Microsoft Corporation。保留所有权利。

C:Userscheng>echo %PROCESSOR_IDENTIFIER%
Intel64 Family 6 Model 158 Stepping 10, GenuineIntel

C:Userscheng>
C:Userscheng>echo %PROCESSOR_LEVEL%
6

C:Userscheng>
C:Userscheng>echo %RANDOM%
25197

C:Userscheng>
C:Userscheng>echo %NUMBER_OF_PROCESSORS%
12

C:Userscheng>
C:Userscheng>echo %OS%
Windows_NT

C:Userscheng>

%PROCESSOR_IDENTIFIER% – Outputs processor identifier. %PROCESSOR_LEVEL% – Outputs processor level. %RANDOM% – This variable prints a random number from 0 through 32767 %NUMBER_OF_PROCESSORS% – Outputs the number of physical and virtual cores. %OS% – Windows_NT

References

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/192313.html原文链接:https://javaforall.cn

0 人点赞