In Windows, is there any shell/PowerShell command to list user environment variable and system environment variable separately?
If I do -
SET TEMP
Use the following batch file:
@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
To use from a command line replace %%
with %
.
Output:
System variable TEMP = %SystemRoot%\TEMP
Current user variable TEMP = %USERPROFILE%\AppData\Local\Temp
Note that the HKEY_CURRENT_USER
takes precedance (but for some reason %USERPROFILE%
is expanded to a shortname when evaluating %TEMP%
):
echo %USERPROFILE%
USERPROFILE=C:\Users\DavidPostill
echo %TEMP%
C:\Users\DAVIDP~1\AppData\Local\Temp