Why can't I use %USERPROFILE% in %PATH%?
Andrew Henderson
On my Windows 7 machine, using the System Properties > Environment Variables tool, I try to add %USERPROFILE%\Bin to the system variable PATH. For some reason, that doesn't work, even though %SystemRoot%\system32 works fine.
When I try to run commands from the console, files in my Bin folder are not found, even though files in the System32 folder are found.
The only difference between UserProfile and SystemRoot that I can see is that the former is a user variable while the latter is a system variable.
echo %USERPROFILE%\Bin yields c:\Users\zano, and if I add c:\Users\zano\Bin explicitly, everything work fine.
What's the problem here?
3 Answers
System variables are set before user variables are. Consequently, at the time system variables are being set, none of your user variables exist yet.
You may be able to create a new user variable called PATH and set it to "%USERPROFILE%\Bin;%PATH%". I have not tested it, but it may do what you want. USERPROFILE might still not be set, though, so you might need to hard-code the path into your user variable, but at least it won't affect other users on the computer.
Stephen Jennings was right, but just a little clarity. In Windows, if the User variable Path exists, it is automatically appended to the System variable Path. The User variable Path is permitted to use %UserProfile% while the System variable gets the literal text "%UserProfile%".
So creating User variable "Path" and setting it to %UserProfile%\Bin was all that was needed.
Example 1:
System Variable Path = C:\WINDOWS\ User Variable Path = %UserProfile%\Bin
User's path will be
C:\WINDOWS;C:\Users\User\Bin
Example 2:
System Variable Path = C:\WINDOWS\;%UserProfile%\Bin
User Variable Path is not set at all.
User's path will be
C:\WINDOWS\;%UserProfile%\Bin
You don't want Example 2.
Similar to what Stephen said but
Create a user environment variable called PATH Within this you can use %USERPROFILE% correctly - USERPROFILE is expanded before user section is processed. This user PATH will be automatically appended to the system path so no need to add the %PATH% part.
e.g.
System variable: PATH=c:\path1 User variable PATH=%USERPROFILE%\path2
Resulting path: PATH=c:\path1;C:\Users\myuser\path2