windows 普通用户如何在Windows Server 2008 R2中设置用户环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1492733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set user environment variables in Windows Server 2008 R2 as a normal user?
提问by AlexCode
In older versions of Windows, it was just open the Control Panel, select the System applet, select the Advanced tab, and then hit the Environment variables button. As a normal user, you could edit the "User variables" but not the "System variables".
在旧版本的 Windows 中,只需打开控制面板,选择系统小程序,选择高级选项卡,然后点击环境变量按钮。作为普通用户,您可以编辑“用户变量”,但不能编辑“系统变量”。
In Windows Server 2008 R2, if I try to hit the Advanced System settings option in the System applet, it prompts for the Administrator password.
在 Windows Server 2008 R2 中,如果我尝试点击系统小程序中的高级系统设置选项,它会提示输入管理员密码。
回答by AlexCode
You can also use this direct command line to open the Advanced System Properties:
您还可以使用此直接命令行打开高级系统属性:
sysdm.cpl
Then go to the Advanced Tab -> Environment Variables
然后转到高级选项卡-> 环境变量
回答by AlexCode
OK I found it. Arg, an exercise in frustration. They left the old window menu traversal path for changing environment variables in there, but limited access to administrators only. As a normal user, if you want to change it, you need to go through a different set of options to arrive at the same frigging window.
好的,我找到了。Arg,一种沮丧的练习。他们离开了旧的窗口菜单遍历路径以更改其中的环境变量,但仅限管理员访问。作为普通用户,如果要更改它,则需要通过一组不同的选项才能到达相同的窗口。
Control Panel-> User Accounts-> User Accounts-> Change my environment variables.
控制面板->用户帐户->用户帐户->更改我的环境变量。
回答by Edgard Concha
Step by step instructions:
分步说明:
- Go to Control Panel \System and Security\System
- Click on Change Settings
- Go to “Advance” tab
- Click on Environment Variables
- 转到控制面板\系统和安全\系统
- 点击更改设置
- 转到“高级”选项卡
- 点击环境变量
回答by h0r41i0
Under "Start" enter "environment" in the search field. That will list the option to change the system variables directly in the start menu.
在“开始”下的搜索字段中输入“环境”。这将列出直接在开始菜单中更改系统变量的选项。
回答by TimT
This can be done from the command line using the SETX
command. For example to 'move' your temporary files to another disk:
这可以使用SETX
命令从命令行完成。例如将临时文件“移动”到另一个磁盘:
SETX TEMP d:\tmp
回答by excitoon
In command line prompt:
在命令行提示符下:
set __COMPAT_LAYER=RUNASINVOKER
SystemPropertiesAdvanced.exe
Now you can set user environment variables.
现在您可以设置用户环境变量。
回答by salim ali
I created a godmode folder on the desktop. just create a new folder on the desktop and call it GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} it will name the folder as godmode and populate the content with various config options, you can then just type in ENVIRO in the search to find the relevant config option, open it and it opens sysdm.cpl in the advanced tab, you can change the environment variables from there.
我在桌面上创建了一个godmode文件夹。只需在桌面上创建一个新文件夹并将其命名为 GodMode。{ED7BA470-8E54-465E-825C-99712043E01C} 它会将文件夹命名为 Godmode 并使用各种配置选项填充内容,然后您只需在搜索中输入 ENVIRO要找到相关的配置选项,打开它并在高级选项卡中打开 sysdm.cpl,您可以从那里更改环境变量。
回答by user3347790
There are three ways
有三种方式
1) This runs the GUI editor for the user environment variables. It does exactly what the OP wanted to do and does not prompt for administrative credentials.
1) 这将运行用户环境变量的 GUI 编辑器。它完全符合 OP 想要做的事情,并且不会提示输入管理凭据。
rundll32.exe sysdm.cpl,EditEnvironmentVariables
(bonus: This works on Windows Vista to Windows 10 for desktops and Windows Server 2008 through Server 2016. It does not work on Windows NT, 2000, XP, and 2003. However, on the older systems you can use sysdm.cpl without the ",EditEnvironmentVariables" parameter and then navigate to the Advanced tab and then Environment Variables button.)
(奖励:这适用于 Windows Vista 到 Windows 10 台式机和 Windows Server 2008 到 Server 2016。它不适用于 Windows NT、2000、XP 和 2003。但是,在较旧的系统上,您可以使用 sysdm.cpl 而无需",EditEnvironmentVariables" 参数,然后导航到高级选项卡,然后导航到环境变量按钮。)
2) Use the SETX command from the command prompt. This is like the set command but updates the environment that's stored in the registry. Unfortunately, SETX is not as easy to use as the built in SET command. There's no way to list the variables for example. Thus it's impossible to do something such as appending a folder to the user's PATH variable. While SET will display the variables you don't know which ones are user vs. system variables and the PATH that's shown is a combination of both.
2) 在命令提示符下使用 SETX 命令。这类似于 set 命令,但会更新存储在注册表中的环境。不幸的是,SETX 不像内置的 SET 命令那样易于使用。例如,没有办法列出变量。因此,不可能执行诸如将文件夹附加到用户的 PATH 变量之类的操作。虽然 SET 将显示您不知道哪些是用户变量和系统变量的变量,但显示的 PATH 是两者的组合。
3) Use regedit and navigate to HKEY_CURRENT_USER\Environment
3) 使用 regedit 并导航到 HKEY_CURRENT_USER\Environment
Keep in mind that changes to the user's environment does not immediately propagate to all processes currently running for that user. You can see this in a command prompt where your changes will not be visible if you use SET. For example
请记住,对用户环境的更改不会立即传播到当前为该用户运行的所有进程。您可以在命令提示符中看到这一点,如果您使用 SET,您的更改将不可见。例如
rem Add a user environment variable named stackoverflow that's set to "test"
setx stackoverflow test
set st
This should show all variables whose names start with the letters "st". If there are none then it displays "Environment variable st not defined
".
Exit the command prompt and start another. Try set st
again
and you'll see
这应该显示名称以字母“st”开头的所有变量。如果没有,则显示“ Environment variable st not defined
”。退出命令提示符并启动另一个。再试set st
一次,你会看到
stackoverflow=test
To delete the stackoverflow variable use
删除stackoverflow变量使用
setx stackoverflow ""
It will respond with "SUCCESS: Specified value was saved.
" which looks strange given you want to delete the variable. However, if you start a new command prompt then set st
will show that there are no variables starting with the letters "st"
它将响应“ SUCCESS: Specified value was saved.
”,这看起来很奇怪,因为您要删除该变量。但是,如果您启动新的命令提示符,set st
则会显示没有以字母“st”开头的变量
(correction - I discovered that setx stackoverflow ""
did not delete the variable. It's in the registry as an empty string. The SET
command though interprets it as though there is no variable. if not defined stackoverflow echo Not defined
says it's not defined.)
(更正 - 我发现setx stackoverflow ""
没有删除变量。它在注册表中作为一个空字符串。SET
尽管该命令将它解释为没有变量。if not defined stackoverflow echo Not defined
说它没有定义。)