Windows用户环境variables与系统环境variables

Windows中,是否有任何shell / Powershell命令分别列出用户环境variables和系统环境variables。 如果我做 –

SET TEMP 

Windows将显示“用户环境variables”而不是“系统variables”。

我正在寻找shell命令/开关来分别显示这些variables。

Solutions Collecting From Web of "Windows用户环境variables与系统环境variables"

在PowerShell中,没有cmdlet,但可以在Environment类中使用底层的.NET方法:

 Write-Host "Machine environment variables" [Environment]::GetEnvironmentVariables("Machine") Write-Host "User environment variables" [Environment]::GetEnvironmentVariables("User") # This should be the same as 'Get-ChildItem env:', although it isn't sorted. Write-Host "Process environment variables" [Environment]::GetEnvironmentVariables("Process") 

使用下面的批处理文件:

 @echo off for /f "tokens=3 usebackq" %%a in (`reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ^| findstr TEMP`) do @echo System variable TEMP = %%a for /f "tokens=3 usebackq" %%a in (`reg query "HKEY_CURRENT_USER\Environment" ^| findstr TEMP`) do @echo Current user variable TEMP = %%a 

从命令行使用%%替换%

输出:

 System variable TEMP = %SystemRoot%\TEMP Current user variable TEMP = %USERPROFILE%\AppData\Local\Temp 

请注意, HKEY_CURRENT_USER采用precedance(但由于某种原因, %USERPROFILE%在评估%TEMP%时扩展为一个简称):

 echo %USERPROFILE% USERPROFILE=C:\Users\DavidPostill echo %TEMP% C:\Users\DAVIDP~1\AppData\Local\Temp