The question pretty much says it all; I have users who do not have permission to edit their own PATH
environment variable and if they need to have it modified for some reason, they need to log out so an Admin can log in and change the PATH
for them, before the user logs back in again. This isn't ideal. Can it be done in a better way?
-
Just curious - but how exactly are you preventing users from changing their own default environment? Are you just denying them access to My Computer / Properties / Advanced / Environment Variable? They could still modify HKCU/Environment through a variety of methods. – Cooper Apr 04 '11 at 13:15
-
See also http://superuser.com/questions/189654/how-to-get-access-to-environment-variables-in-windows/189755 – Pat Jul 29 '13 at 19:17
-
Group policy preferences? Just a thought. – Simon Catlin Jul 29 '13 at 21:19
6 Answers
For accounts without admin privileges:
Open "User Accounts" and choose "Change my environment variables" (http://support.microsoft.com/kb/931715).
This dialog will show you your current user variables as well as the system variables. You may need to add a local PATH variable if you haven't already.
To update your Path to include the Python 3.3 directory, for instance, click New:
Variable Name: PATH Variable Value: %PATH%;C:\Python33
This creates a local PATH by taking the current system PATH and adding to it.
- 369
- 3
- 3
-
2I've got to think this answers, "*I have users who do not have permission to edit their own PATH*...", and does so *permanently*, better than the rest. Very nicely done. Wonder why clicking that from the My Computer is admin protected if this isn't? Just protect non-local fields the same way the UI does when accessed this way. – ruffin Sep 10 '14 at 15:10
-
Unfortunately, this doesn't seem to work. When my users attempt this, it prompts them for the admin password. As I enter the admin password, it ends up opening the dialog for MY path statement. – Tanoshimi Dec 08 '21 at 18:51
My Computer / Properties / Advanced / Environment Variables. Changes there take effect immediately except for already open command prompt windows. No need to log out and back in.
NOTE: If you don't have access to that window, you might be able to get it by running rundll32 sysdm.cpl,EditEnvironmentVariables
from the Run window or command-line.
- 7,355
- 16
- 54
- 72
- 27,262
- 12
- 53
- 108
-
regular users on my network are not able to change their own environment variables like this, unless I can open that screen with elevated privs via "run as..." or something similar, this won't work for me – ninesided Jul 01 '09 at 07:00
You can always invoke a cmd shell with administrator rights (or any other runas method), and use a tool such as SETX to modify the path permanently. Existing shells and/or running programs will probably be using the old path, but any new shell/program will use the new settings.
- 1,162
- 3
- 11
- 19
In a command prompt you can do:
set PATH=C:\somedir;%PATH%
but this only changes it for the command prompt (and any apps launched from the command prompt). Assuming you want this to apply to everything the user does you change the users environment variables. Right click My Computer, Properties, Advanced, Environment variables and in the "User variables for add a variable:
PATH = C:\whatever
When the user logs in this gets added to the system wide path.
- 7,756
- 1
- 22
- 34
-
I need to change the order of entries already in the PATH, so adding removing from the User Variables doesn't work for me in this case – ninesided Jul 01 '09 at 07:01
-
`setx`, as @Berzemus mentioned, can edit the system PATH variable (the `/m` switch) permanently. – Pat Jul 29 '13 at 19:12
In addition to the answers above, you can also update the registry (which has the advantage of being scriptable):
The PATH variable is stored in HKEY_CURRENT_USER\Environment.
To read the current path:
reg query HKEY_CURRENT_USER\Environment /v PATH
To append a value c:\somedir to the path:
reg add HKEY_CURRENT_USER\Environment /v PATH /d "%PATH%;c:\somedir"
Note that processes read the environment when being launched, so you would have to restart the process for it to get the new path.
Update: Another way I found is to run:
rundll32 sysdm.cpl,EditEnvironmentVariables
Again, this applet edits the registry and has the same effect as the above.
- 151
- 1
- 2
The user can set a PATH variable at a command-prompt that will override the system-wide PATH variable, even if the user doesn't have "Administrator" rights. The change will take effect for new processes the user starts from that command prompt. (The existing Explorer process, and any other processes the user is running when the change is made, will not "see" the change.)
- 141,071
- 19
- 191
- 328