Windows 10 / 11 环境变量 (用户变量与系统变量)

发布时间:2026/7/27 19:41:23
Windows 10 / 11 环境变量 (用户变量与系统变量) Windows 10 / 11 环境变量 {用户变量与系统变量}1. 环境变量 (environment variables)1.1. 用户变量1.2. 系统变量1.3. Windows 10 - echo %path%1.4. Windows 11 - echo %path%1.5. 用户变量和系统变量的优先级1.5.1. 普通变量1.5.2. Path 变量2. Setting the path and variables in Windows 103. List of environment variables in Windows 10References1. 环境变量 (environment variables)环境变量 (environment variables) 是在操作系统中用来指定操作系统运行环境的一些参数。环境变量是在操作系统中一个具有特定名字的对象它包含了一个或者多个应用程序所使用到的信息。Windows 和 DOS 操作系统中的path环境变量当要求系统运行一个程序而没有告诉它程序所在的完整路径时系统除了在当前目录下面寻找此程序外还应到path中指定的路径去找。用户通过设置环境变量来更好的运行进程。environment variables环境变量 user variables用户变量 system variables系统变量环境变量可分为用户变量与系统变量两类在注册表中都有对应的项。Win R打开运行窗口输入regedit然后Enter进入注册表编辑器。1.1. 用户变量用户变量所在位置HKEY_CURRENT_USER\Environment1.2. 系统变量系统变量所在位置HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\EnvironmentC:\Program Files\Common Files\Oracle\Java\javapath;D:\VulkanSDK\1.3.216.0\Bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\Program Files\platform-tools;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86_64;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86;C:\Program Files\dotnet\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%JAVA_HOME%\bin;在原有变量的基础上添加英文状态下的分号然后添加路径名。不要删除原先的系统变量只要用分号隔开然后添加路径名最后也要加上分号。添加路径之后要保存再重启cmd确保生效。1.3. Windows 10 -echo %path%Microsoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %path% C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Users\cheng\AppData\Local\Microsoft\WindowsApps; C:\Users\cheng C:\Users\chengecho %PATH% C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Users\cheng\AppData\Local\Microsoft\WindowsApps; C:\Users\cheng1.4. Windows 11 -echo %path%Microsoft Windows [版本 10.0.22621.1265] (c) Microsoft Corporation。保留所有权利。 C:\Users\chengecho %PATH% D:\VulkanSDK\1.3.216.0\Bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\Program Files\platform-tools;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86_64;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86;C:\Program Files\dotnet\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\cheng\AppData\Local\Microsoft\WindowsApps;C:\Program Files\NVIDIA Corporation\NVSMI;;D:\Program Files\Microsoft VS Code\bin C:\Users\cheng C:\Users\chengecho %path% D:\VulkanSDK\1.3.216.0\Bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\Program Files\platform-tools;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86_64;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86;C:\Program Files\dotnet\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\cheng\AppData\Local\Microsoft\WindowsApps;C:\Program Files\NVIDIA Corporation\NVSMI;;D:\Program Files\Microsoft VS Code\bin C:\Users\cheng设置系统信息高级系统设置 - 高级环境变量环境变量可以理解为系统的视线 (作用域) 范围配置进入环境变量的可执行程序就是进入了系统的视线范围。打开命令窗口后输入程序名系统就会把在其视线内的 (环境变量内) 的程序找出来。如果程序没有配置进入环境变量的话那系统自然就找不到。系统变量针对所有用户起作用为了安全起见一般配置用户环境变量。用户变量只对当前用户起作用不建议为了省事而配置系统环境变量。1.5. 用户变量和系统变量的优先级1.5.1. 普通变量如果在用户变量和系统变量中创建同名变量那么 Windows 会将用户变量覆盖系统变量。在 cmd 中输出的是用户变量中该变量的值。对于普通变量用户环境变量优先级高于系统环境变量。系统会先检查用户变量之后再检查系统变量。Microsoft Windows [版本 10.0.22621.1265] (c) Microsoft Corporation。保留所有权利。 C:\Users\chengecho %TEMP% C:\Users\cheng\AppData\Local\Temp C:\Users\cheng C:\Users\chengecho %TMP% C:\Users\cheng\AppData\Local\Temp C:\Users\cheng1.5.2. Path 变量​1. 环境变量不区分大小写path / PATH / Path表示指定可执行文件的搜索路径。2.echo %path%可以得到path变量的值 (系统变量中的值与用户变量中的值的组合)用户变量path内容会跟在系统变量path内容的后面。3. 对于Path变量系统环境变量优先级高于用户环境变量。4. Windows 系统在执行用户命令时若用户未给出文件的绝对路径则首先在当前目录下寻找相应的可执行文件。然后在系统变量的path / PATH / Path路径中查找如果找不到再到用户变量的path / PATH / Path路径中查找。Windows 对于Path变量的处理方式是将用户变量的Path添加到系统变量Path后面。Windows 在查找指令的时候是按Path中的路径从前往后找直至在某个路径中找到了该指令。如果系统变量Path中有对应指令的话Windows 就不会再去用户变量Path中查找。2. Setting the path and variables in Windows 10From thedesktop, right-click theComputericon and selectProperties. If you don’t have aComputericon on yourdesktop, clickStart, right-click theComputeroption in theStartmenu, and selectProperties.Click theAdvanced System Settingslink in the left column.In theSystem Propertieswindow, click on theAdvancedtab, then click theEnvironment Variablesbutton near the bottom of that tab.In theEnvironment Variableswindow, highlight thePathvariable in theSystem variablessection and click theEditbutton. 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 otherenvironment variablesby highlighting the variable in theSystem variablessection and clickingEdit. If you need to create a newenvironment variable, clickNewand enter thevariable nameandvariable value.此电脑 - 高级系统设置环境变量3. List of environment variables in Windows 10Microsoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %COMMONPROGRAMFILES% C:\Program Files\Common Files C:\Users\cheng C:\Users\chengecho %COMMONPROGRAMFILES(x86)% C:\Program Files (x86)\Common Files C:\Users\cheng C:\Users\chengecho %COMSPEC% C:\Windows\system32\cmd.exe C:\Users\cheng C:\Users\chengecho %HOMEDRIVE% C: C:\Users\cheng C:\Users\chengecho %HOMEPATH% \Users\cheng C:\Users\cheng C:\Users\chengecho %SYSTEMROOT% C:\Windows C:\Users\chengecho %WINDIR% C:\Windows C:\Users\cheng C:\Users\chengecho %TMP% C:\Users\cheng\AppData\Local\Temp C:\Users\cheng C:\Users\chengecho %TEMP% C:\Users\cheng\AppData\Local\Temp C:\Users\cheng%COMMONPROGRAMFILES%-C:\Program Files\Common Files%COMMONPROGRAMFILES(x86)%-C:\Program Files (x86)\Common Files%COMSPEC%-C:\Windows\System32\cmd.exe%HOMEDRIVE%-C:%HOMEPATH%-C:\Users\username%SYSTEMROOT%-C:\Windows%WINDIR%-C:\Windows%TMP%-C:\Users\username\AppData\Local\Temp%TEMP%-C:\Users\username\AppData\Local\TempMicrosoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %APPDATA% C:\Users\cheng\AppData\Roaming C:\Users\cheng C:\Users\chengecho %ALLUSERSPROFILE% C:\ProgramData C:\Users\cheng C:\Users\chengecho %CD% C:\Users\cheng C:\Users\cheng C:\Users\chengecho %CMDEXTVERSION% 2 C:\Users\cheng C:\Users\chengecho %DATE% 2020/05/04 周一 C:\Users\cheng C:\Users\chengecho %ERRORLEVEL% 0 C:\Users\cheng C:\Users\chengecho %LOCALAPPDATA% C:\Users\cheng\AppData\Local C:\Users\cheng C:\Users\chengecho %LOGONSERVER% \\YONGQIANG C:\Users\cheng C:\Users\chengecho %PATH% C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Users\cheng\AppData\Local\Microsoft\WindowsApps;C:\Program Files\NVIDIA Corporation\NVSMI; C:\Users\cheng%APPDATA%-C:\Users\username\AppData\Roaming%ALLUSERSPROFILE%-C:\ProgramData%CD%- 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%DATE%- 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\AppData\Local%LOGONSERVER%-\\domain_logon_server%PATH%-C:\Windows\system32;C:\Windows;Microsoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC C:\Users\cheng C:\Users\chengecho %PROGRAMDATA% C:\ProgramData C:\Users\cheng C:\Users\chengecho %PROGRAMFILES% C:\Program Files C:\Users\cheng C:\Users\chengecho %PROGRAMW6432% C:\Program Files C:\Users\cheng C:\Users\chengecho %PROGRAMFILES(X86)% C:\Program Files (x86) C:\Users\cheng C:\Users\chengecho %PROMPT% $P$G C:\Users\cheng C:\Users\chengecho %SYSTEMDRIVE% C: C:\Users\cheng C:\Users\chengecho %TIME% 12:34:57.39 C:\Users\cheng C:\Users\chengecho %USERNAME% cheng C:\Users\cheng%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%-$P$G%SYSTEMDRIVE%-C:%TIME%- Similarly, it gives you current time according to the time format preferences%USERNAME%-usernameMicrosoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %USERPROFILE% C:\Users\cheng C:\Users\cheng C:\Users\chengecho %USERDOMAIN% YONGQIANG C:\Users\cheng C:\Users\chengecho %USERDOMAIN_ROAMINGPROFILE% YONGQIANG C:\Users\cheng C:\Users\chengecho %PUBLIC% C:\Users\Public C:\Users\cheng C:\Users\chengecho %PSMODULEPATH% C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules C:\Users\cheng C:\Users\chengecho %ONEDRIVE% C:\Users\cheng\OneDrive C:\Users\cheng C:\Users\chengecho %CMDCMDLINE% C:\Windows\system32\cmd.exe C:\Users\cheng C:\Users\chengecho %COMPUTERNAME% YONGQIANG C:\Users\cheng C:\Users\chengecho %PROCESSOR_REVISION% 9e0a C:\Users\cheng%USERPROFILE%-C:\Users\username%USERDOMAIN%- Userdomain associated with current user%USERDOMAIN_ROAMINGPROFILE%- Userdomain associated with roaming profile%PUBLIC%-C:\Users\Public%PSMODULEPATH%-%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\%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 revisionMicrosoft Windows [版本 10.0.17763.1158] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\chengecho %PROCESSOR_IDENTIFIER% Intel64 Family 6 Model 158 Stepping 10, GenuineIntel C:\Users\cheng C:\Users\chengecho %PROCESSOR_LEVEL% 6 C:\Users\cheng C:\Users\chengecho %RANDOM% 25197 C:\Users\cheng C:\Users\chengecho %NUMBER_OF_PROCESSORS% 12 C:\Users\cheng C:\Users\chengecho %OS% Windows_NT C:\Users\cheng%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_NTReferences[1] Yongqiang Cheng (程永强), https://yongqiang.blog.csdn.net/[2] Windows 10 / 11 环境变量 (用户变量与系统变量), https://mp.weixin.qq.com/s/cozTACQwVyP0JMjOwwjCCw