Get PATH value in CMD (Environment variable)

0

Is there any way to get the value of the PATH environment variable through the command prompt?

For example:

REG QUERY HKCU\Environment /v PATH

It throws me the value of the PATH variable of the current user (it can also be done with the one of the system writing a different route, but I only need the user one), but together with that it also tells me the name of the variable and of what type it is (by default it comes in REG_SZ but it can also be REG_SZ_EXPAND).

What I want to do is save the value of PATH in some variable to then do operations on it, for example, a chain concatenation, etc.

Important Note: I can not do something like:     set x =% path% because this combines the PATH value of the user with the system, and I only need the user's PATH value.

    
asked by codenoschool 30.07.2017 в 01:51
source

4 answers

1

If the command that you put actually throws the PATH of the current user, then you simply have to take its value from the output of the REG QUERY command, which is in the third element separated by spaces, by means of a FOR /F command:

@echo off

for /F "tokens=3" %%a in ('REG QUERY HKCU\Environment /v PATH') do set "x=%%a"

echo PATH del usuario: "%x%"
    
answered by 26.08.2017 / 15:24
source
1

You can use these two ways:

echo %PATH&


SET PATH

The drawback of the last one is that it starts with PATH =

    
answered by 11.08.2017 в 18:03
1

There is no environment variable that you can access from the system symbol that shows you only the PATH environment variable assigned to the user.

As a reference for the different areas of the environment variables, the editor can be viewed directly with the following command:

rundll32 sysdm.cpl,EditEnvironmentVariables
    
answered by 11.08.2017 в 21:12
0

% HOMEPATH% stores the full path for the user's default folder; if you also require the unit it is in% HOMEDRIVE%.

If you need a list of variables: link

    
answered by 30.07.2017 в 02:19