如何在命令行MS-DOS中使用Set命令列出,设置和获取Windows环境变量?

Operating systems have a lot of configurations. These configurations are stored in different ways in different locations. One of the most common storage for some generic information like Username, operating system path etc. is environment variables. In this tutorial we will look how to list, get and set Windows operating system environment variables in details. We will use set command mainly. Set command lists, sets and gets single or all environment variables.

操作系统有很多配置。 这些配置以不同的方式存储在不同的位置。 环境变量是某些通用信息(如用户名,操作系统路径等)的最常见存储之一。 在本教程中,我们将详细介绍如何列出,获取和设置Windows操作系统环境变量。 我们将主要使用set命令。 设置命令列表,设置并获取单个或所有环境变量。

帮帮我 (Help)

More information about set command ca be printed with /? option.

有关设置命令的更多信息可以用/?打印/? 选项。

$ set /?
Help
Help
帮帮我

句法(Syntax)

Syntax of the set command is very simple. [variable] and [string] parts are optional and used according to situation

set命令的语法非常简单。 [variable][string]部分是可选的,并根据情况使用

SET [variable=[string]]

列出所有环境变量 (List All Environment Variables)

Environment variables holds a lot of information about the operating system and user . All these information can be listed just issuing the set command without any parameter like below.

环境变量包含有关操作系统和用户的大量信息。 只需发出set命令即可列出所有这些信息,而无需发出任何如下所示的参数。

$ set
List All Environment Variables
List All Environment Variables
列出所有环境变量

获取/打印单个环境变量(Get/Print Single Environment Variable)

In previous example we have listed all environment variables without selecting particular one. We can print only single variable just proving the variable name to the set command. In this example we will print the values of APPDATA environment variable.

在前面的示例中,我们列出了所有环境变量,但没有选择特定的变量。 我们仅可以在set命令中证明变量名称即可打印单个变量。 在此示例中,我们将打印APPDATA环境变量的值。

$ set APPDATA
Get/Print Single Environment Variable
Get/Print Single Environment Variable
获取/打印单个环境变量

更改/创建环境变量(Change/Create Environment Variable)

Now the last function of the set command. We can create  or change and environment variable and its value by giving both the variable name and the variable data. In this example we create a new variable named Test with value 1

现在是set命令的最后一个功能。 我们可以通过提供变量名称和变量数据来创建或更改环境变量及其值。 在此示例中,我们创建一个名为Test的新变量,其值为1

$ set Test=1

找回家的路 (Get Home Path)

Home is the current users location where his personal files and folders stored. This path can be printed like below.

主页是当前用户存储其个人文件和文件夹的位置。 可以像下面这样打印此路径。

$ set HOMEPATH

获取登录服务器 (Get Logon Server)

Logon server is used to authenticate the user to login a system. In active directory system user credentials are authenticated in these authority servers.

登录服务器用于对用户进行身份验证以登录系统。 在活动目录系统中,在这些授权服务器中对用户凭据进行身份验证。

$ set LOGONSERVER

获取路径变量 (Get Path Variable)

Path variable is used to find executable files. Path variable stored more than one path and if a command is issued these path are checked for this command executables to run.

路径变量用于查找可执行文件。 路径变量存储了多个路径,如果发出命令,则检查这些路径以使该命令可执行文件运行。

$ set PATH

获取程序文件路径 (Get Program Files Path)

Windows operating system stores built-in and 3 party applications files and folder in Program Files directory. This directory path can be printed like below.

Windows操作系统将内置的3方应用程序文件和文件夹存储在Program Files目录中。 可以像下面这样打印此目录路径。

$ set ProgramFiles

获取系统根 (Get System Root)

Windows operating system files, folders and libraries are stored in System Root and this root directory generally named windows . By default this path is C:\Windows . The system root can be printed like below.

Windows操作系统文件,文件夹和库存储在System Root目录中,该根目录通常称为windows 。 默认情况下,此路径为C:\Windows 。 系统根目录可以如下打印。

$ set SystemRoot

获取用户名 (Get Username)

The currently logged users user name can be printed like below.

当前登录用户的用户名可以如下打印。

$ set USERNAME
LEARN MORE  Memcached Replace Operation with Python Examples
通过Python示例了解更多Memcached替换操作

翻译自: https://www.poftut.com/how-to-list-set-get-windows-environment-variables-with-set-command-in-command-line-ms-dos/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值