IT:AD:Environment Variables:HowTo:Tips Regarding PATH
Summary
Setting the PATH is such a common activity for developers that one would think it straightforward.
It is. Until it doesn't work.
Notes
PATH is parsed literally
Only ; is used to separate directories in PATH. As a result, every character has to be treated literally – including spaces.
The above fact is sometimes incorrectly interpreted on the net as “don't use spaces, wrap everything in quotes”.
Ref: * http://superuser.com/a/457353 * Actually tested this myself on WinServer2012…it's correct.
Avoid spaces
That's not correct – you can if you are careful (see above)
### Using Special Environment Variables is preferred.
There's no harm in using Environment Variables to make Environment Variables
- Use
%SystemRoot%instead ofc:\ - Use
%ProgramFiles(x86)%instead ofc:\Program Files(x86)* Use%ProgramFiles%instead ofc:\Program Files
RefreshEnv doesn't work
I'm not sure what RefreshEnv actually does…But it doesn't work for either User or Machine PATH settings.
You have to close/reopen a new IT:AD:Powershell CLI.
Setting a User PATH is trickier than it looks
- Yes, You can set a User
PATHEnvironment Variable. - Yes, it will be merged with the Machine
PATHEnvironment Variable
But it if it's a Service Account (eg: Srv-CI ), you'll be surprised at how weird it can get…
Using a GUI
On Windows Server 2012, if you are the RDP-ing in as Srv-CI, when you click Start, System, Advanced System Settings, Environment Variables, you'll be prompted for an Administrator password.
And if you give it, you'll be presented with the screen to edit User Environment Variables. Unfortunately, you'll be updating the Administrator's Environment Variables – not the Service Accounts…
Instead, use Start, Control Panel\User Accounts\User Accounts, then Change My Environment Variables
Using BAT commands
If you want to do it from the CLI, see: IT:AD:SetX
Using Powershell
Powershell does work (see above regarding RefreshEnv):
[Environment]:: SetEnvironmentVariable("PATH","...etc...", "User")
Ref: * IT:AD:Powershell:HowTo:Snippets:Work with Environment Variables * IT:AD:PowerShell:HowTo:Snippets:Refresh Environment Variables
Watch out for the total Length
Finally, at least on Windows Server 2003, once the system PATH passes 1920 characters, the user PATH environment variable is no longer merged with it to set the process PATH environment variable, even though the full system PATH (even if larger) will be included in the process PATH variable.
Example
Purely for safe keeping, the following is an example of a system PATH at one point in time:
* C:\Program Files (x86)\SenchaSDKTools-2.0.0-beta3;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Nuget;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files (x86)\Common Files\Teleca Shared;C:\Program Files (x86)\InstallAware\InstallAware NX;C:\Program Files\nodejs\;C:\Program Files\Microsoft\Web Platform Installer\;c:\PHP\;C:\Program Files (x86)\Graphviz 2.28;C:\Program Files (x86)\Git\cmd;C:\Program Files\TortoiseGit\bin