重启后无法正确识别PATH环境变量(Win 8.1)(PATH environment variable not correctly recognized after reboot (Win 8.1)

系统教程 行业动态 更新时间:2024-06-14 16:57:39
重启后无法正确识别PATH环境变量(Win 8.1)(PATH environment variable not correctly recognized after reboot (Win 8.1))

我的PATH变量有问题。 我已经在版本7.1.1 Final中安装了JBOSS-AS并设置了环境变量(希望它是正确的术语,因为我的操作系统是德语)JBOSS_HOME到我安装它的路径:C:\ Program Files \ jboss-as -7.1.1.Final。

然后我添加了%JBOSS_HOME%\ bin; 到PATH系统变量。 重新启动cmd之后,我可以通过它的名称调用该bin文件夹中的所有内容(大多数是* .bat文件),而无需命名通向它的完整路径。 所以进展顺利。 但后来我重新启动了我的电脑,它不再工作了。 我必须转到环境变量,选择PATH,编辑...并单击确定(不更改任何内容)以使cmd再次识别它。 奇怪的是,echo%JBOSS_HOME%返回正确的路径并且echo%PATH%返回:

C:\ WINDOWS \ system32; C:\ WINDOWS; C:\ WINDOWS \ System32 \ Wbem; C:\ WINDOWS \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Python27; C:\ Program Files \ nodejs \; C :\ Program Files(x86)\ Git \ bin; C:\ Program Files(x86)\ Git \ cmd;%JAVA_HOME%\ bin;%M2_HOME%\ bin;%JBOSS_HOME%\ bin; C:\ Program Files(x86 )\记事本++; C:\用户\马库斯\应用程序数据\漫游\ NPM

所以%JBOSS_HOME%\ bin仍在那里......

任何想法这里发生了什么?

I am having issues with my PATH variable. I have installed JBOSS-AS in the version 7.1.1 Final and set the environment variable (hope it's the correct term, since my OS is in German) JBOSS_HOME to the path I installed it to: C:\Program Files\jboss-as-7.1.1.Final.

Then I added %JBOSS_HOME%\bin; to the PATH system variable. After restarting the cmd I could call everything in that bin folder (mostly *.bat-files) by it's name without naming the full path leading to it. So that went well. But then I rebooted my PC and it didn't work anymore. I had to go to the environment variables, select PATH, edit... and klick OK (without changing anything) to make the cmd recognize it again. Odd thing is, that echo %JBOSS_HOME% returns the correct path and echo %PATH% returns:

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Python27;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;%JAVA_HOME%\bin;%M2_HOME%\bin;%JBOSS_HOME%\bin;C:\Program Files (x86)\Notepad++;C:\Users\Markus\AppData\Roaming\npm

So %JBOSS_HOME%\bin is still in there...

Any Idea what is happening here?

最满意答案

感谢@MichaelS我至少现在知道该问题的解决方法:

当你通过命令行或批处理文件添加环境变量时似乎工作正常,但我不知道为什么,因为环境变量GUI看起来和以前一样,当我手动添加它们时。

这是我使用的批处理文件的内容(对于命令行,见下文):

setx JBOSS_HOME "C:\Program Files\jboss-as-7.1.1.Final" /M setx PATH_OLD "%PATH%" /M setx PATH "%PATH%%%JBOSS_HOME%%\bin;" /M

setx设置(和覆盖!)环境变量。 多个%-signs将转义%JBOSS_HOME%变量,因此它不会以“C:\ Program Files \ jboss-as-7.1.1.Final”结尾。 %%将是单个% ,而单个%将使变量扩展到它的内容 。 因此,在这种情况下,%PATH%将成为%PATH%变量的内容,而%% JBOSS_HOME %%将成为%JBOSS_HOME%。 / M使系统范围内的环境变量不仅适用于您的用户。 为此,您需要使用管理员权限打开该文件,否则将无法正常工作。

如果你没有直接使用批处理文件而是使用命令行 ,我认为转义字符是^,但我没试过。 所以命令是:

setx JBOSS_HOME "C:\Program Files\jboss-as-7.1.1.Final" /M setx PATH_OLD "%PATH%" /M setx PATH "%PATH%^%JBOSS_HOME^%\bin;" /M

此外,我必须事先重命名名为PATH的用户环境变量 (之后撤消它),因为%PATH%连接系统和用户环境变量,这会将用户变量的内容添加到系统变量中。

我只设置PATH_OLD以防出现问题,我相信它是推荐的但不是我想做的事情所必需的。

Thanks to @MichaelS I at least now know a workaround for that problem:

It seems to work fine when you add the environment variables via command line or batch file, but I don't know why, since the environment variables GUI looks the same as before, when I added them manually.

Here's the content of the batch file (for command line see below) I used:

setx JBOSS_HOME "C:\Program Files\jboss-as-7.1.1.Final" /M setx PATH_OLD "%PATH%" /M setx PATH "%PATH%%%JBOSS_HOME%%\bin;" /M

setx sets (and overrides!) environment variables. The multiple %-signs are to escape the %JBOSS_HOME%-variable so it does not end up as "C:\Program Files\jboss-as-7.1.1.Final". %% is going to be a single %, while a single % will make the variable expand to it's content. So in this case %PATH% will become the content of the %PATH% variable while %%JBOSS_HOME%% will simply become %JBOSS_HOME%. /M makes the environment variables system-wide and not only for your user. For this you will need to open the file with admin rights, otherwise it won't work.

If you're not using a batch file but the command line directly, the escape character is ^, I think, but I did not try that out. So the commands would be :

setx JBOSS_HOME "C:\Program Files\jboss-as-7.1.1.Final" /M setx PATH_OLD "%PATH%" /M setx PATH "%PATH%^%JBOSS_HOME^%\bin;" /M

Also, I had to rename the user environment variable named PATH beforehand (and undo it afterwards), because %PATH% concatenates the system und user environment variables, which would add the content of the user variable to the system variable.

I only set PATH_OLD in case something goes wrong, I believe it's recommended but not necessary for what I wanted to do.

更多推荐

本文发布于:2023-04-13 12:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e365f2c9011120172db7c88b675d098c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重启   环境变量   正确   Win   PATH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!