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?