I know how to set system or user specific environment variables:
Now, the problem is that the PATH
variable is treated such that the value you enter for the user PATH will be automatically appended to the system PATH and that will be the effective PATH variable.
That is, say I have
(SYSTEM) PATH=C:\Windows\System32;C:\Program Files\Foo\bin;...
and (USER) PATH=C:\Program Files\Bar\bin
(note that there is not %PATH%
in this value)
then the resulting environment variable for this user will be:
(effective) PATH=C:\Windows\System32;C:\Program Files\Foo\bin;...;C:\Program Files\Bar\bin
However, I would rather like that for a very specific OS user account the PATH environment variable should have the bar\bin
directory at the beginning of the PATH instead of at the end.
Is there a proper way to tell windows to completely override the PATH
variable of a user with the value for that user instead of appending it to the system PATH
variable?
Note: Obviously, from a batch file, all this doesn't matter as you can set and tweak the env.vars as you like.
Answer
If you only need this to work for command prompt sessions, create a profile/init batch file and configure it in the registry, per https://stackoverflow.com/questions/17404165/how-to-run-a-command-on-command-prompt-startup-in-windows. E.g.,
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun ^
/t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
Then simply make modifications to the PATH in that batch file. E.g.,
SET USER_PATH=c:\whatever
SET PATH=%USER_PATH%;%PATH%
No comments:
Post a Comment