Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current users path variable without system path using cmd

When I'm logged in with my standard user (which is also an admin) the command echo %PATH% returns system's path + user's path. How can I get the user's path only?

E.g. when my current user's path is C:\ruby;C:\java\bin and system's path is %SystemRoot%\system32;%SystemRoot% the command above returns %SystemRoot%\system32;%SystemRoot%;C:\ruby;C:\java\bin but I only want to have C:\ruby;C:\java\bin in order to be able to append to user's path permanently without system's path trash included.

My goal is to append a directory to the path variable. I tried to do this with the command setx PATH %PATH%;C:\ruby\bin which ruined my path variable because of the system's path.

like image 551
SimonH Avatar asked Mar 08 '23 20:03

SimonH


1 Answers

Another way using PowerShell.

(Get-ItemProperty HKCU:\Environment).PATH

Or, from a cmd.exe shell.

powershell -NoProfile -Command "(Get-ItemProperty HKCU:\Environment).PATH"

In order to retrieve the variable without interpolation.

(Get-Item -Path HKCU:\Environment).GetValue('PATH', $null, 'DoNotExpandEnvironmentNames')

powershell -NoProfile -Command ^
    "(Get-Item -Path HKCU:\Environment).GetValue('PATH', $null, 'DoNotExpandEnvironmentNames')"
like image 120
lit Avatar answered Mar 10 '23 10:03

lit