默认情况下,Windows使用某些环境变量来允许用户快速访问操作系统中的某些路径和目录。这有助于使Windows更易于导航。通过定义和设置您自己的自定义环境变量,您可以创建应用程序、目录、URL(URLs)等的直接路径和快捷方式。
Windows中的环境变量按百分比 (%) 字符排列。因此,如果您以前没有使用过环境变量,只需启动开始菜单并在搜索框中键入以下任何命令并按Enter即可开始。
%appdata%
%temp%
%userprofile%
%homepath%
请注意(Notice),如果您只是在搜索框中键入术语appdata,它将返回各种不同的结果。但是,如果您在搜索框中键入术语 %appdata%,则您正在调用一个环境变量,您将被带到AppData Roaming目录。
现在您已经稍微习惯了使用环境变量,让我们开始了解如何添加、编辑或删除环境变量。单击(Click)开始按钮并在 搜索框中输入(Start)环境变量。(environment variable)单击编辑系统环境变量( Edit the system environment variables)。
这将打开“系统属性(System Properties)”对话框到“高级(Advanced)”选项卡。单击 底部的环境变量按钮。(Environment Variables)
这将在Windows 10中显示如下所示的环境变量(Environment Variables)对话框。它在Windows 7(Windows 7)中看起来有点不同,但它的工作方式相同。该对话框分为两部分:顶部用于用户变量,底部用于系统变量。
现在,让我们为Windows 10添加一个非常简单的环境变量。单击“用户变量(User variables)”部分下列出的“新建”(New) 按钮。这将显示新用户变量(New User Variable)窗口,您可以在其中定义变量名称(variable name)和变量值( variable value)。
变量名称:(Variable name:)文本区域允许您为环境变量定义一个简单的名称。变量值:( Variable value:)文本区域允许您定义在使用变量名称时触发的路径或其他值。因此,让我们创建一个非常简单的环境变量来启动Help Desk Geek网站。以下是值:
单击“确定(OK)”按钮添加自定义变量,然后单击“环境变量”窗口上的“(Environment Variables)确定(OK)”按钮关闭并应用该变量。
完成后,您现在可以用几种不同的方式测试变量。首先,如果您希望能够从“开始(Start)”菜单启动它,则需要重新启动计算机。由于某种原因,除非您重新启动,否则只能通过使用资源管理器(Explorer)或使用运行(Run)命令来调用它。
探险家:
运行命令(Windows 键 + R)
开始菜单搜索框
使用上述三种方法中的任何一种,Windows将启动您的默认浏览器并打开一个选项卡到Help Desk Geek网站。很酷(Pretty)吧?您还可以创建自定义环境变量以将Explorer启动到特定目录。
如果您经常需要导航到文件层次结构深处的目录,这会派上用场。例如,这是我必须经常访问的目录:
C:\Users\aseem\Documents\HOA Stuff\Legal\Contracts\Appeals\Notes
无需单击所有这些目录,我只需创建一个新的用户环境变量,如下所示:
现在,在Explorer中,我所要做的就是在地址栏中输入%HOA%,它会将我带到那个目录!您还可以单击“浏览目录(Browse Directory)”或“浏览文件( Browse File)”按钮以更轻松地包含所需文件夹或文件的路径。
文件选项很有趣,因为它意味着您还可以创建环境变量来启动程序。例如,您可以将环境变量指向系统上的任何EXE文件。当您调用变量时,它将启动程序。
上面的示例是一个不好的示例,因为单击Start并输入cal比输入 % CAL % 更容易。但是,如果您有一个自定义的可执行程序文件存储在 PC 上的某个随机目录中,这是一种无需去寻找即可启动它的简单方法。享受!
Create Custom Environment Variables in Windows
By default, Windows υses certain environment variables tо allow users to quickly access certain paths and directories within the оperаting system. This helps to make Wіndows еasier to navigate. By defining and setting up your own custom environment variables, you can create direct рaths and shortcuts to apps, directorieѕ, URLs and more.
Environment variables in Windows are queued by percent (%) characters. So, if you’ve not used environment variables before, you can get started simply by launching the start menu and typing any of the following commands into the search box and pressing Enter.
%appdata%
%temp%
%userprofile%
%homepath%
Notice how if you were to simply type the term appdata into the search box, it would return a wide variety of different results. However, if you type the term %appdata% into the search box, you are invoking an environment variable and you are taken to the AppData Roaming directory.
Now that you’re slightly accustomed to using environment variables, let’s get started on how you add, edit or delete environment variables. Click on the Start button and type in environment variable into the search box. Click on Edit the system environment variables.
This will open up the System Properties dialog to the Advanced tab. Click on the Environment Variables button at the bottom.
This will bring up the Environment Variables dialog as shown below in Windows 10. It looks a bit different in Windows 7, but it works the same way. The dialog is split in two: the top for user variables and the bottom for system variables.
Now, let’s add a very simple environment variable to Windows 10. Click the New button listed under the User variables section. This will present you with the New User Variable window, where you can define a variable name and a variable value.
The Variable name: text area lets you define a simple name for the environment variable. The Variable value: text area lets you define a path or other value that is triggered when the variable name is used. So, let’s create a very simple environment variable to launch the Help Desk Geek website. Here are the values:
Click the OK button to add your custom variable, and click the OK button on the Environment Variables window to close and apply the variable.
With that done, you can now test the variable in a couple of different ways. Firstly, if you want to be able to launch it from the Start menu, you’ll need to restart your computer. For some reason, unless you restart, it can only be invoked by using Explorer or by using the Run command.
Explorer:
Run Command (Windows key + R)
Start Menu Search Box
Using any of the three methods above, Windows will launch your default browser and open a tab to the Help Desk Geek website. Pretty cool right? You can also create a custom environment variable to launch Explorer into a specific directory.
This can come in handy if you often have to navigate to a directory that is deep in your file hierarchy. For example, here is a directory I have to access often:
C:\Users\aseem\Documents\HOA Stuff\Legal\Contracts\Appeals\Notes
Instead of having to click through all those directories, I can just create a new user environment variable like below:
Now, in Explorer, all I have to do is type %HOA% in the address bar and it will bring me right to that directory! You can also click on the Browse Directory or Browse File buttons to more easily include the path to your desired folder or file.
The file option is interesting because it means you can also create an environment variable to launch a program. For example, you can point an environment variable to any EXE file on your system. When you invoke the variable, it will launch the program.
The above example is a bad example because it’s easier to click on Start and type in cal than it is to type in %CAL%. However, if you have a custom executable program file stored in some random directory on your PC, this is an easy way to launch it without having to go look for it. Enjoy!