如何从系统属性获取 Windows 操作系统环境变量 [英] How to get Windows OS Environment Variable from System Property
问题描述
我遇到了一个关于系统属性环境变量的奇怪问题.
I am encountering a strange problem about System Property environment variable.
如你所知,我们可以打开Computer->Property->Advanced System Settings->Advanced->System Environment Variables->User Variables for admin
As you know, we can open Computer->Property->Advanced System Settings->Advanced->System Environment Variables->User Variables for admin
我将 Variable TEMP' 值更改为 C:\mytemp\ 并单击确定以保存它.
I change Variable TEMP' value to C:\mytemp\ and click OK to save it.
然而,在命令行中,当我回显 %TEMP%
时,它仍然显示原始路径,C:\Users\admin\AppData\Local\Temp
.
However, In command line, when I echo %TEMP%
, it still show original path, C:\Users\admin\AppData\Local\Temp
.
当我在资源管理器中输入 %TEMP% 时,它会转到 C:\mytemp
When I input %TEMP% in explorer, it will go to C:\mytemp
现在我想要用户 API 来获取路径,GetEnvironmentVariable()
也将返回与命令行中的 echo %TEMP% 相同的路径.我怎样才能像exploer那样获得路径.提前致谢.
Now I want to user API to get the path, GetEnvironmentVariable()
will also return path which is same as echo %TEMP% in command line. how can I get the path as exploer did.
Thanks in advance.
附注.操作系统是Win7 x86
PS. OS is Win7 x86
推荐答案
通过计算机->属性->高级系统设置->高级->系统环境变量->用户变量更改环境路径会立即生效.但是请注意,那些正在运行的程序不会获得最新的环境变量.
Changing environment path through Computer->Property->Advanced System Settings->Advanced->System Environment Variables->User Variables will take effect immediately. However, please be noted that those programs which are running will not get the latest environment variable.
所以我认为你只是没有为 echo 重新打开一个新的 cmd.
So I thought that you simply didn't reopen a new cmd for echo.
打开一个新的cmd,再次echo,会显示新的路径.
Open a new cmd, and echo again, the new path will be shown.
这篇关于如何从系统属性获取 Windows 操作系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!