Saturday, April 8, 2017

windows - How to append to the user %PATH% from command line

I found plenty of questions like this one on StackExchange but no one work in my specific case.



I would like to easily add literally %FOO% to the user environment variable PATH.



I found the solution below. Unfortunately it doesn't work as expected.



for /f "skip=2 tokens=3*" %a in ('reg query HKCU\Environment /v PATH') do @if [%b]==[] ( @setx PATH "%~a;%FOO%" ) else ( @setx PATH "%~a %~b;%FOO%" )



It doesn't work if:




  • The user PATH variable doesn't exist

  • The user PATH exists and is empty

  • The user PATH is almost 255 char long.



Moreover it doesn't add the %FOO% literally but expands it.




Is there any possibility to easily do it?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...