你有没有想过环境变量?也许一些 IT 管理员或计算机极客提到了它们。某些程序是否(Did)开始出现故障并返回涉及环境变量的错误?是不是刚考试,唯一不(Did)知道怎么填的项目是:“环境变量是____________。”?无论您出于何种原因想了解更多关于它们的信息,您都来对了地方。在本文中,我们将向您展示您需要了解的环境变量、它们的工作原理以及它们为何对 Windows 的健康至关重要:
Windows中的环境变量是什么?
那么什么是环境变量呢?简而言之,环境变量是描述应用程序和程序运行环境的变量。各种程序都使用环境变量来回答以下问题:我安装的计算机的名称是什么?(name of the computer)运行我的用户帐户的名称是什么?我当前的工作目录是什么?Windows安装在哪里?这台计算机上存储的临时文件在哪里?此用户帐户的 OneDrive 文件夹在哪里?
在 Windows 中,环境变量具有名称和值(environment variables have a name and value)。例如,变量windir (“ Windows目录”的缩写)可能具有值"C:\Windows"或您安装Windows的其他路径。
(Environment)Windows 10中的(Windows 10)环境用户和系统变量
另一个标准变量名为PATH。许多程序需要知道在哪里可以找到特定的文件,PATH变量会告诉他们在哪里可以找到他们需要的文件。这些程序会自动查找PATH变量,因此您不必在每次运行程序时都输入它。该变量的值由许多用户目录组成。这些目录是由安装在计算机上的不同应用程序设置的,它们因系统而异。
环境变量的概念存在于大多数操作系统中,从Linux到 macOS 再到Windows。原则上,它们的含义相同,但实现和使用的方式不同。
环境变量的类型:用户变量和系统变量
有两种类型的变量:特定于每个用户帐户的用户变量和适用于所有用户帐户的系统变量。
用户环境变量的值因用户而异。(User environment variables have values that differ from user to user.)顾名思义,它们特定于您的用户帐户。它们存储用户特定的数据,例如您的用户配置文件的位置、为您的帐户存储临时文件的文件夹、您的 OneDrive 文件夹的位置等。该用户帐户可以编辑它们,但其他用户帐户不能。这些变量可以由用户、Windows或使用用户特定位置的不同程序创建(created)和编辑。(edited)
系统变量是全局的,任何用户都不能更改。(System variables are global and cannot be changed by any user.)它们的值对于所有用户帐户都是相同的。它们指的是关键系统资源位置,例如安装Windows的文件夹、 (Windows)Program Files的位置等。这些变量由Windows、不同的程序和驱动程序设置。
我在哪里可以找到Windows的环境变量?
在Windows 10中,使用任务栏上的搜索框查找环境(environment)。然后,单击或点击“编辑系统环境变量”(“Edit the system environment variables”)搜索结果。
在Windows 10(Windows 10)中使用搜索打开环境变量
在 Windows 7 中,在开始菜单(Start Menu)搜索框中键入environment 。然后,单击“编辑您帐户的环境变量”(“Edit environment variables for your account”)或“编辑系统环境变量”。(“Edit the system environment variables.”)
在Windows 7(Windows 7)中使用搜索打开环境变量
或者,如果您使用 Windows 10,则可以使用“设置”应用(use the Settings app)访问环境用户和系统变量。在“设置”(Settings)中,转到“系统”,(System, )然后选择左侧边栏的“关于”页面。(About)然后,单击或点击“高级系统设置”。(“Advanced system settings.”)它会打开“系统属性(System Properties)”窗口,您可以在其中按“高级”选项卡中的“(Advanced)环境变量(Environment Variables)”按钮。
使用设置在Windows 10中查找环境变量(Windows 10)
同样,要在Windows 7(Windows 7)中访问您的环境用户和系统变量,您可以使用控制面板(use the Control Panel)。在控制面板(Control Panel)中,进入系统和安全(System and Security),然后进入系统(System)。在左侧,单击或点击“高级系统设置(Advanced system settings)”链接,打开“系统属性(System Properties)”窗口。在其高级(Advanced)选项卡中,按下面突出显示的环境变量(Environment Variables)按钮。
在Windows 7(Windows 7)中使用控制面板(Control Panel)打开环境变量
在任何Windows操作系统中,如果您知道要键入什么命令,您还可以使用运行窗口(Run window) (Win + R ) 访问您的环境变量。在此窗口中,键入命令rundll32.exe sysdm.cpl,EditEnvironmentVariables,然后按Enter或单击OK。
rundll32.exe sysdm.cpl,EditEnvironmentVariables
无论(Regardless)您选择使用哪种方法,“环境变量(Environment Variables)”窗口现在都应该打开。
在顶部,环境变量(Environment Variables)显示您的用户变量,在底部,它显示系统变量,对Windows中存在的所有用户帐户有效。
Windows中的环境变量(Variables)窗口
如何在命令提示符(Command Prompt)或PowerShell中查看环境变量(PowerShell)
如果您是Command Prompt的粉丝,您可以使用命令(Command Prompt)集(set)查看所有环境变量,无需任何其他参数。在 Windows 中启动命令提示符,键入(Start the Command Prompt)set,然后按Enter。
使用(Use)set获取CMD中的环境变量列表(CMD)
如果您更喜欢PowerShell,请打开它,键入命令Get-ChildItem Env:并按Enter。
使用(Use)Get-ChildItem Env: 获取PowerShell中的环境变量列表(PowerShell)
列出了所有环境变量,但它们不会根据其类型(用户或系统变量)进行拆分。
如果您只想查看系统变量,请在PowerShell中使用以下命令:[Environment]::GetEnvironmentVariables("Machine")。
PowerShell中的系统变量列表:[ Environment ]::Get Environment Variables(" Machine ")
如果您只想列出用户变量,请运行以下命令:[Environment]::GetEnvironmentVariables("User")。
PowerShell中的用户变量列表:[ Environment ]::Get Environment Variables(" Machine ")
哪些是Windows中的标准环境变量?
每台Windows(Windows)计算机上都有一长串变量。最常用的是 OS、PATH和TEMP等变量。您可以在Wikipedia(Wikipedia)上找到整个列表及其所有默认值:环境变量 - Microsoft Windows 上的默认值(Environment variables - Default Values on Microsoft Windows)。
您将环境用户和系统变量用于什么?
现在您知道如何回答这个问题了:“什么是环境变量?”。正如您从本教程中看到的那样,在使用Windows(Windows)程序时,环境变量既不容易找到也不可见。它们由操作系统以及您安装的不同程序和驱动程序在后台进行管理。但是,它们对于操作系统和已安装应用程序的正常运行至关重要。如果您在不知道自己在做什么的情况下更改基本系统变量的值,您将通过导致系统故障来体验这些环境变量的重要性。在你走之前,请在下面发表评论并告诉我们你是如何在Windows中使用环境变量的。
What are environment variables in Windows? -
Have you еνer wondered about environment variables? Maybe some IT admin or computer geek was mentioning them. Did some programs start malfunctioning and retυrning errors referring to environment variables? Did you just hаve an exam, and the only item you didn’t know how to fill in was: "envіronment variables are ____________."? No matter your reasons for wanting to leаrn more about them, you arrived at thе rіght place. In this article, we show you what you need to know about environment variables, how they work, and why they are essential for Windows’ wellbeing:
What are environment variables in Windows?
So what is an environment variable? Environment variables are, in short, variables that describe the environment in which apps and programs run. All kinds of programs use environment variables to answer questions like: What’s the name of the computer where I’m installed? What is the name of the user account that is running me? What is my current working directory? Where is Windows installed? Where are the temporary files stored on this computer? Where is the OneDrive folder for this user account?
In Windows, environment variables have a name and value. For example, the variable windir (short for "Windows directory") may have the value "C:\Windows" or another path where you installed Windows.
Environment user and system variables in Windows 10
Another standard variable is named PATH. Many programs need to know where to find specific files, and the PATH variable tells them where they can find what they need. Those programs automatically look for a PATH variable, so you don’t have to type it all in every time you run the program. This variable has a value consisting of many user directories. These directories are set by the different applications installed on the computer, and they vary widely from system to system.
The concept of environment variables exists in most operating systems, from Linux to macOS to Windows. In principle, they mean the same thing but the way they are implemented and used differs.
Types of environment variables: user variables and system variables
There are two types of variables: user variables, specific to each user account, and system variables that apply to all user accounts.
User environment variables have values that differ from user to user. As their name implies, they are specific to your user account. They store user-specific data, like the location of your user profile, the folder where temporary files are stored for your account, the location of your OneDrive folder, and so on. That user account can edit them, but other user accounts cannot. These variables can be created and edited by the user, by Windows, or by different programs working with user-specific locations.
System variables are global and cannot be changed by any user. Their values are the same for all user accounts. They refer to critical system resource locations, like the folder where Windows is installed, the location of Program Files, and so on. These variables are set by Windows, different programs, and drivers.
Where can I find the environment variables from Windows?
In Windows 10, use the search box on the taskbar to look for environment. Then, click or tap on the “Edit the system environment variables” search result.
Using search to open the enviroment variables in Windows 10
In Windows 7, type environment in the Start Menu search box. Then, click on “Edit environment variables for your account” or “Edit the system environment variables.”
Using search to open the enviroment variables in Windows 7
Alternatively, if you use Windows 10, you can use the Settings app to access the environment user and system variables. In the Settings, go to System, and select the About page on the left sidebar. Then, click or tap on “Advanced system settings.” It opens the System Properties window, where you can press the Environment Variables button from the Advanced tab.
Using Settings to find the enviroment variables in Windows 10
Similarly, to access your environment user and system variables in Windows 7, you can use the Control Panel. In the Control Panel, go to System and Security and then to System. On the left, click or tap the “Advanced system settings” link, which opens the System Properties window. In its Advanced tab, press the Environment Variables button highlighted below.
Using Control Panel to open the enviroment variables in Windows 7
In any Windows operating system, you can also use the Run window (Win + R) to access your environment variables if you know what command to type. In this window, type the command rundll32.exe sysdm.cpl,EditEnvironmentVariables, and press Enter or click OK.
rundll32.exe sysdm.cpl,EditEnvironmentVariables
Regardless of which method you chose to use, the Environment Variables window should be open now.
At the top, the Environment Variables displays your user variables, and on the bottom, it shows the system variables, valid for all user accounts existing in Windows.
Environment Variables window in Windows
How to view environment variables in the Command Prompt or PowerShell
If you are a fan of the Command Prompt, you can see all the environment variables with the command set, without any other parameters. Start the Command Prompt in Windows, type set, and press Enter.
Use set to get the list of environment variables in CMD
If you prefer PowerShell, open it, type the command Get-ChildItem Env: and press Enter.
Use Get-ChildItem Env: to get the list of environment variables in PowerShell
All the environment variables are listed, but they are not split depending on their type (user or system variables).
If you want to see only the system variables, in PowerShell, use this command instead: [Environment]::GetEnvironmentVariables("Machine").
List of system variables in PowerShell: [Environment]::GetEnvironmentVariables("Machine")
And if you want to list only the user variables, run this command: [Environment]::GetEnvironmentVariables("User").
List of user variables in PowerShell: [Environment]::GetEnvironmentVariables("Machine")
Which are the standard environment variables in Windows?
There is a long list of variables existing on each Windows computer. The most used are variables like OS, PATH, and TEMP. You can find the entire list and all their default values on Wikipedia: Environment variables - Default Values on Microsoft Windows.
What are you using environment user and system variables for?
Now you know how to answer the question: “What are environment variables?”. As you can see from this tutorial, environment variables are neither easy to find nor visible in any way while working with Windows programs. They are managed in the background by the operating system and the different programs and drivers you install. However, they are essential to the proper functioning of the operating system and of your installed apps. If you change the value of essential system variables without knowing what you are doing, you will get to experience just how vital these environment variables are by causing your system to malfunction. Before you go, comment below and tell us how you are using environment variables in Windows.