从命令行列出所有环境变量?

时间:2011-03-16 15:22:25

标签: windows command-line environment-variables prompt

我想知道是否可以从Windows的命令提示符列出所有环境变量。

相当于PowerShell gci env:(或ls env:dir env:)的内容。

11 个答案:

答案 0 :(得分:1215)

只是做:

SET

您还可以SET prefix查看名称以prefix开头的所有变量。

例如,如果您只想从环境变量中读取derbydb,请执行以下操作:

set derby 

......您将获得以下内容:

DERBY_HOME=c:\Users\amro-a\Desktop\db-derby-10.10.1.1-bin\db-derby-10.10.1.1-bin

答案 1 :(得分:147)

Jon有正确的答案,但要用一些语法糖来详细说明......

SET | more

使您可以一次查看一页变量,而不是整批,或

SET > output.txt

将输出发送到文件output.txt,您可以在记事本或其他任何地方打开...

答案 2 :(得分:80)

列出Powershell中的所有环境变量:

Get-ChildItem Env:

来源:https://technet.microsoft.com/en-us/library/ff730964.aspx

答案 3 :(得分:75)

只需从cmd运行set

  

显示,设置或删除环境变量。如果不使用参数,set将显示当前的环境设置。

答案 4 :(得分:14)

我会说SET命令并不真正打印所有环境变量。 例如,我们可以回显诸如CD,DATE,TIME之类的变量,但它们未在SET输出中列出。

例如,获得可用于批量写作的完整变量列表会很有趣。

答案 5 :(得分:12)

您可以在cmd中使用SET

要显示当前变量,只需SET即可

要显示某些变量,例如' PATH',请使用SET PATH

如需帮助,请输入set /?

答案 6 :(得分:4)

如果要查看刚刚设置的环境变量,则需要打开一个新的命令窗口。 "使用setx变量设置的变量仅在将来的命令窗口中可用,而不是在当前命令窗口中。" (https://technet.microsoft.com/en-us/library/cc755104(v=ws.11).aspx#BKMK_examples

答案 7 :(得分:4)

不要浪费时间在注册表中搜索<​​/ p>

reg query“HKLM \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment”

返回少于设置命令

答案 8 :(得分:4)

如其他线程所述,您可以使用onSelectPage(thePage: string) { //page(1/4) /* /* var slash = Number(page.indexOf('/')); var length = slash - 5; page = page.substr(5, length); */ let page = Number(thePage); let productDisplay = this._searchProductService.products; this.products = []; this.productsNextColumn = []; let pageNumber = Number(page) - 1; this.pageNumber = pageNumber; this.pageDisplay = pageNumber + 1; if(this.isClicked) { productDisplay = this.theClickedQueries; if(productDisplay.length > 0) productDisplay = this.theClickedQueries; else productDisplay = this._searchProductService.products; } let productDisplayLength = productDisplay.length; if(this.pageNumber == 0) { this.startDisplay = 0; this.endDisplay = this.PRODUCTS_PER_PAGE/2; this.previousPage = 'disabled'; for(let i=this.startDisplay; i <this.endDisplay; i++) { this.products.push(productDisplay[i]); } let nextColumn = this.endDisplay + this.PRODUCTS_PER_PAGE/2; for(let i=this.endDisplay; i<nextColumn; i++){ this.productsNextColumn.push(productDisplay[i]); } } //Click on other pages.. else { this.previousPage = ''; this.startDisplay = this.pageNumber * this.PRODUCTS_PER_PAGE; this.endDisplay = this.startDisplay + this.PRODUCTS_PER_PAGE/2; if(productDisplayLength > this.endDisplay) { for(let i=this.startDisplay; i <this.endDisplay; i++) this.products.push(productDisplay[i]); let nextColumn = this.endDisplay + this.PRODUCTS_PER_PAGE/2; if(productDisplayLength >= nextColumn) { for(let i=this.endDisplay; i<nextColumn; i++) this.productsNextColumn.push(productDisplay[i]); if(productDisplayLength > nextColumn) this.nextPage = ''; else this.nextPage = 'disabled'; } else { for(let i=this.endDisplay; i<productDisplayLength; i++){ this.productsNextColumn.push(productDisplay[i]); } this.nextPage = 'disabled'; } } else { for(let i=this.startDisplay; i <productDisplayLength; i++) this.products.push(productDisplay[i]); } } if(this.advertisements[this.pageNumber] != null) this.advertisement = this.advertisements[this.pageNumber]; } 列出所有环境变量或使用

set获取具有值的特定变量。

set [environment_varible]可用于从空间中删除变量。

答案 9 :(得分:0)

非扩展变量 -

用户变量 -

reg query HKEY_CURRENT_USER\Environment

系统变量-

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

扩展变量 -

在 CMD 中 -

SET

在 Powershell 中 -

来源 - https://devblogs.microsoft.com/scripting/powertip-use-windows-powershell-to-display-all-environment-variables/

dir env:

答案 10 :(得分:-2)

此命令将列出 Linux 终端上的所有环境变量。

$ printenv