Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get User environment variables from cmd prompt

I am hoping there is a simple answer for this is. Is there a command that would give me a list of all User Environment variables? (or value of a user Environment variable if it exists). I know there is 'set' command, however it lists both user and system variables. I am running a script and I would like to know if a particular environment variable exists in user variables. Only other option would be using registry information. But I would like to know if this is possible with a commandline or something similar.

Thanks

like image 762
Nik Avatar asked Nov 20 '15 19:11

Nik


People also ask

How can I see the user environment variable?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables.

How do I find my environment variable path?

Select Start, select Control Panel. double click System, and select the Advanced tab. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it.

How do I get environment variables in Windows?

In the System > About window, click the Advanced system settings link at the bottom of the Device specifications section. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.


1 Answers

Querying the registry is probably the most simple method of returning only User environment variables:

reg query HKEY_CURRENT_USER\Environment

This is an example of what output is returned:

λ reg query HKEY_CURRENT_USER\Environment

HKEY_CURRENT_USER\Environment
    ChocolateyLastPathUpdate    REG_SZ    132148451031142736
    ChocolateyToolsLocation    REG_SZ    C:\tools
    ip    REG_SZ    ipconfig /all | findstr /IR "ipv4 ethernet adapter" | findstr /IRV "description tunnel vpn dial bluetooth [2-9]:$" | findstr /LV "*"
    Path    REG_EXPAND_SZ    C:\PATH\gnuwin32\bin;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
    QB    REG_SZ    tasklist /FI "IMAGENAME eq qbittorrent.exe"
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
like image 79
Travis Runyard Avatar answered Oct 08 '22 15:10

Travis Runyard