PATH variable different when cmd was run through the context menu

瘦欲@ 提交于 2019-12-10 08:40:47

问题


I just spent the last hour on trying to find out why the hell my PATH variable wasn't updating for my cmd.exe. Now I figured out that it kind of did update, but only for certain conditions...
I updated it via Win+Break -> Change Settings -> Advanced -> Environment Variables...

Now when I open a new commandline via Win+R -> cmd -> Enter the PATH variable shows whatever I set it to.
But when I open a new commandline via Shift+Rightclick into folder -> Open command window here, the PATH variable shows outdated content.

My question: Why is this happening, what can I do about it?


回答1:


As pointed out by Hans Passant, the problem was that running cmd via the explorer's context menu spawns cmd as a child process to the explorer causing it to inherit the environment variables from explorer.exe instead of acquiring them itself. And since a process usually only loads the environment variables once in the beginning and doesn't listen for changes, the explorer inherited outdated variables to the cmd instance.

So the solution would be to simply restart explorer.exe.



来源:https://stackoverflow.com/questions/29878326/path-variable-different-when-cmd-was-run-through-the-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!