Is it possible to set a environment variable at the system level from a command prompt in Windows 7 (or even XP for that matter). I am running from an elevated command prompt.
是否可以在Windows 7(或者甚至是XP)中从命令提示符处在系统级别设置环境变量。我从一个提升的命令提示符运行。
When I use the set
command (set name=value
), the environment variable seems to be only valid for the session of the command prompt.
当我使用set命令(set name = value)时,环境变量似乎仅对命令提示符的会话有效。
6 个解决方案
#1
156
The XP Support Tools (which can be installed from your XP CD) come with a program called setx.exe
:
XP支持工具(可以从XP CD安装)附带一个名为setx.exe的程序:
C:\Program Files\Support Tools>setx /?SETX: This program is used to set values in the environmentof the machine or currently logged on user using one of three modes.1) Command Line Mode: setx variable value [-m] Optional Switches: -m Set value in the Machine environment. Default is User....For more information and example use: SETX -i
I think Windows 7 actually comes with setx
as part of a standard install.
我认为Windows 7实际上是将setx作为标准安装的一部分。
#2
112
Simple example for how to set JAVA_HOME with setx.exe
in command line:
有关如何在命令行中使用setx.exe设置JAVA_HOME的简单示例:
setx JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
This will set environment variable "JAVA_HOME" for current user. If you want to set a variable for all users, you have to use option "-m". Here is an example:
这将为当前用户设置环境变量“JAVA_HOME”。如果要为所有用户设置变量,则必须使用选项“-m”。这是一个例子:
setx -m JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
Note: you have to execute this command as Administrator.
注意:您必须以管理员身份执行此命令。
Note: Make sure to run the command setx from an command-line Admin window
注意:确保从命令行管理窗口运行命令setx
#3
17
If you set a variable via SETX, you cannot use this variable or its changes immediately. You have to restart the processes that want to use it.
如果通过SETX设置变量,则无法立即使用此变量或其更改。您必须重新启动要使用它的进程。
Use the following sequence to directly set it in the setting process too (works for me perfectly in scripts that do some init stuff after setting global variables):
使用以下顺序在设置过程中直接设置它(在设置全局变量后执行某些初始化操作的脚本中完美地适用于我):
SET XYZ=testSETX XYZ test
#4
2
For XP, I used a (free/donateware) tool called "RAPIDEE" (Rapid Environment Editor), but SETX is definitely sufficient for Win 7 (I did not know about this before).
对于XP,我使用了一个名为“RAPIDEE”(快速环境编辑器)的(免费/捐赠软件)工具,但是对于Win 7来说,SETX肯定是足够的(之前我不知道这个)。
#5
1
Just in case you would need to delete a variable, you could use SETENV from Vincent Fatica available at http://barnyard.syr.edu/~vefatica.Not exactly recent ('98) but still working on Windows 7 x64.
为了防止您需要删除变量,您可以使用Vincent Fatica的SETENV,网址为http://barnyard.syr.edu/~vefatica。不是最近的('98),但仍在使用Windows 7 x64。
#6
1
System variables can be set through CMD and registry For ex. reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH
系统变量可以通过CMD和注册表设置。 reg查询“HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment”/ v PATH
All the commonly used CMD codes and system variables are given here: Set Windows system environment variables using CMD.
这里给出了所有常用的CMD代码和系统变量:使用CMD设置Windows系统环境变量。
Open CMD and type Set
打开CMD并键入Set
You will get all the values of system variable.
您将获得系统变量的所有值。
Type set java to know the path details of java installed on your window OS.
键入set java以了解窗口OS上安装的java的路径详细信息。
#1
156
The XP Support Tools (which can be installed from your XP CD) come with a program called setx.exe
:
XP支持工具(可以从XP CD安装)附带一个名为setx.exe的程序:
C:\Program Files\Support Tools>setx /?SETX: This program is used to set values in the environmentof the machine or currently logged on user using one of three modes.1) Command Line Mode: setx variable value [-m] Optional Switches: -m Set value in the Machine environment. Default is User....For more information and example use: SETX -i
I think Windows 7 actually comes with setx
as part of a standard install.
我认为Windows 7实际上是将setx作为标准安装的一部分。
#2
112
Simple example for how to set JAVA_HOME with setx.exe
in command line:
有关如何在命令行中使用setx.exe设置JAVA_HOME的简单示例:
setx JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
This will set environment variable "JAVA_HOME" for current user. If you want to set a variable for all users, you have to use option "-m". Here is an example:
这将为当前用户设置环境变量“JAVA_HOME”。如果要为所有用户设置变量,则必须使用选项“-m”。这是一个例子:
setx -m JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
Note: you have to execute this command as Administrator.
注意:您必须以管理员身份执行此命令。
Note: Make sure to run the command setx from an command-line Admin window
注意:确保从命令行管理窗口运行命令setx
#3
17
If you set a variable via SETX, you cannot use this variable or its changes immediately. You have to restart the processes that want to use it.
如果通过SETX设置变量,则无法立即使用此变量或其更改。您必须重新启动要使用它的进程。
Use the following sequence to directly set it in the setting process too (works for me perfectly in scripts that do some init stuff after setting global variables):
使用以下顺序在设置过程中直接设置它(在设置全局变量后执行某些初始化操作的脚本中完美地适用于我):
SET XYZ=testSETX XYZ test
#4
2
For XP, I used a (free/donateware) tool called "RAPIDEE" (Rapid Environment Editor), but SETX is definitely sufficient for Win 7 (I did not know about this before).
对于XP,我使用了一个名为“RAPIDEE”(快速环境编辑器)的(免费/捐赠软件)工具,但是对于Win 7来说,SETX肯定是足够的(之前我不知道这个)。
#5
1
Just in case you would need to delete a variable, you could use SETENV from Vincent Fatica available at http://barnyard.syr.edu/~vefatica.Not exactly recent ('98) but still working on Windows 7 x64.
为了防止您需要删除变量,您可以使用Vincent Fatica的SETENV,网址为http://barnyard.syr.edu/~vefatica。不是最近的('98),但仍在使用Windows 7 x64。
#6
1
System variables can be set through CMD and registry For ex. reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH
系统变量可以通过CMD和注册表设置。 reg查询“HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment”/ v PATH
All the commonly used CMD codes and system variables are given here: Set Windows system environment variables using CMD.
这里给出了所有常用的CMD代码和系统变量:使用CMD设置Windows系统环境变量。
Open CMD and type Set
打开CMD并键入Set
You will get all the values of system variable.
您将获得系统变量的所有值。
Type set java to know the path details of java installed on your window OS.
键入set java以了解窗口OS上安装的java的路径详细信息。