0

How can I set user environmental variables (such as PATH) from a non-administrator account on Windows 10?

I am aware that there is a button for what I want: See here But as I click it, nothing happens.

You may as well check out this forum post for another guy who has the same problem.

I am running windows 10 pro v1511 build10586.545

Edit: It was a bug of Windows 10. Updating to the newest Update (Anniversary Update) fixed it.

InsOp
  • 105
  • 1
  • 9
  • Possible duplicate of [How can I set user environmental variables (such as PATH) from a non-administrator account on Windows 7](http://superuser.com/questions/165909/how-can-i-set-user-environmental-variables-such-as-path-from-a-non-administrat) – DavidPostill Sep 13 '16 at 21:56
  • @DavidPostill the answer does not apply in windows 10, because, as i stated above, this button is dead – InsOp Sep 13 '16 at 21:58
  • @InsOP Worked for me. I am using Version 1607 Windows 10 Professional – Ramhound Sep 13 '16 at 22:02

1 Answers1

0

The command you want is setx.exe (it's a command-line program). Use setx /? to get usage info, but for your use case it boils down to the following:

setx MYVAR "The value of my variable"

Note that setx doesn't update your current environment variables for the running program (i.e. CMD or Powershell); you'll need to also use the set command to update the variables in the shell.

Two other ways to do this:

  1. Use PowerShell to call the .NET function [System.Environment]::SetEnvironmentVariable(<varname>, <value>, [System.EnvironmentVariableTarget]::User) (you can substitute 1 or "user" for [System.EnvironmentVariableTarget]::User; it's an enum)
  2. Edit the registry directly. Per https://stackoverflow.com/questions/573817/where-are-environment-variables-stored-in-registry, the location is HKCU\Environment. You could, for example, add a value like this (using the reg.exe program): reg add /v <VARNAME> /d <VALUE>

If you want to update your per-user PATH without also adding the all-users (local machine) PATH values to your personal PATH, you'll need to get a little trickier. Using reg query or [System.Environment]::GetEnvironmentVariable(<varname>, [System.EnvironmentVariableTarget]::User), you can get the current value from the registry, instead of getting the process's current value for PATH (which is a concatenation of the user and machine values). Using PS, you could even set this value to a temporary variable:

set mypath $([Environment]::GetEnvironmentVariable("Path", 1)) creates a temporary (local, non-environment) variable called "mypath" and sets it to the current user-specific value of the PATH environment variable (Windows environment variable names are case-insensitive).

echo $mypath to make sure you got it correctly.

set mypath ($mypath + ';C:\foo\bar'); echo $mypath appends C:\foo\bar to the temporary variable and echoes the result back.

setx Path $mypath to update the environment variable with your concatenated string.

set $env:Path ($env:Path + ';C:\foo\bar') to also update the current PowerShell session, or just launch a new one from Windows Explorer (Start, taskbar, whatever).

CBHacking
  • 6,119
  • 2
  • 21
  • 34
  • Thank you for the answer. Is there a maybe a fix for this button I was talking about so I dont have to go to the registry or powershell to do this? And if not, which of the provided methods do change the environment variables permanently? – InsOp Sep 14 '16 at 06:04
  • The most obvious fix is just to update. The "Anniversary update" (v1607, build 14393) is now available, and will probably fix your malfunctioning link; as with @Ramhound, it works for me. If that still doesn't work for some reason, try using your Windows install media to "repair" your installation, or just re-install. – CBHacking Sep 14 '16 at 18:43
  • Every method not explicitly stated to be used for the current process only will make permanent changes. That means `setx`, `[System.Environment]::SetEnvironmentVariable`, and registry editing (such as `reg add`. However, these methods do *not* change the environment variables in the current process, which is why I also include info on doing that. – CBHacking Sep 14 '16 at 18:45
  • thanks - the anniversary update will take up to 3 months to fully rollout. It wont update automacally, but you can update it with this [link](https://www.microsoft.com/en-us/software-download/windows10), which ill do. Will give Feedback whether it works – InsOp Sep 15 '16 at 09:37