
Environment Variables and Path in Windows 10 - archon810
https://plus.google.com/+ArtemRussakovskii/posts/CCM4hXzpRTv
======
alister
What's completely inexplicable is why it took 23 years to do this. Consider
this:

(1) It's self-contained piece of UI code. It's not like this change will
permeate effects throughout the OS.

(2) It's a few man days of work. Let's say that as a super-exaggerated-extreme
estimate, it is still only a few months of work.

(3) Nobody was dependent on the current behavior.

(4) Everybody hated the current behavior. Programmers jumped through hoops
like copying&pasting the strings into an editor, making a change, and pasting
it back.

(5) They had at least 23 years to fix it (since at least Windows 3.1).

There are more plausible explanations about MH370 than there are about
Microsoft's thinking here.

~~~
anon4
What's even more inexplicable is that you can't do the same on Linux. For all
the developer-friendliness of the platform, nothing infuriates me more than
having to edit my PATH/LD_LIBRARY_PATH/etc. by editing my .bashrc and then
having to log out and back in again. Not to mention that programs you start
from the GUI launcher don't source that file so if you need a program to start
with one of them set, you actually need to edit .profile... wait no that
doesn't work, I mean /etc/profile.d/99-my-path.conf... no actually it's
/etc/environment... or is it /etc/profile... oh fuck this I'll just write a
small shell script that sets PATH and launches what I want.

Like... in Windows _motherfucking_ NINETY-FIVE you could edit your PATH
variable without having to restart, why do I have to log out and back in in
2015 for Linux to accept those changes. Why do I have to mess around with
random scripts that may or may not be executed by one of the many steps
launching my session. What is this madness.

~~~
shiro
Isn't just starting a new shell suffice? (Usually I'm lazier and just say ".
~/.bashrc", knowing that it might not be idempotent but I don't care.)

~~~
yokohummer7
If you place environment variables in ~/.bashrc, it would work. However,
generally they are placed in ~/.profile which is read only when a _login
shell_ is launched. (And ~/.bashrc is not even read when you start a GUI
session, anyways.) This is especially problematic in the GUI environment
because in that case the login shell is the desktop environment itself. So you
need to restart the whole environment (close all the windows, logout, and
login) to load the new environment variables.

Windows gets over this problem by letting the login shell (explorer.exe)
reload the environment variables in place. So, if we are to do the same thing
in Linux, we might have to patch bash, zsh, and GNOME etc. to understand the
environment variable change events and reload itself appropriately. I'm not
sure where to start, but I believe this is the one thing that Windows did
right, so I want to see it happen.

~~~
lottin
Changing how the environment works isn't a trivial change, it would have far-
reaching consequences, and every program that reads the environment would need
to be patched, not only the shells and display managers.

~~~
barrkel
If the aim is to replicate how Windows works, only the GUI shell would need to
reload environment variables (i.e. the process that forks when you start
programs using whatever the desktop's idiom is).

~~~
lottin
This seems inconsistent behaviour to me. Some running processes reload the
environment and others don't. Maybe in Windows they can get away with it, but
that doesn't mean it's a good idea.

~~~
darklajid
To be fair: The Windows way is kinda consistent: If the environment definition
was changed, everyone gets a window message. It's just that no one but
explorer.exe cares about that and reacts, as far as I'm aware (Raymond Chen
had a recent article mentioning exactly this).

So, the OS tells everyone 'Hey, you totally could update your environment'.
But your running instance of Skype or whatever just doesn't need to care.

~~~
zastrowm
Raymond Chen article for anyone that is interested:
[http://blogs.msdn.com/b/oldnewthing/archive/2015/09/15/10641...](http://blogs.msdn.com/b/oldnewthing/archive/2015/09/15/10641604.aspx)

------
douche
If we're ragging on ancient Windows history, could Microsoft please make
Notepad kinda usable? Here's two simple changes that would hugely reduce the
incidence of me roaring at my machine when I remote into a server that doesn't
have Notepad++ yet:

1.) Don't set the filter on the file open dialog as .txt, by default, just
make it all files.

2.) Handle newlines properly, even if they are evil Mac or Linux style ones.

For the love of Cthulhu, don't rewrite it as a Modern app, just fix a few of
the things that have been irritating for twenty years.

~~~
lewisl9029
> For the love of Cthulhu, don't rewrite it as a Modern app

I'm honestly curious about this remark.

If Modern apps today were as limited as they were in Windows 8 then I'd
wholeheartedly agree with you. But I actually find Modern apps in Windows 10
to be quite usable now that they can be freely resized and managed like any
regular application.

I personally use several modern apps on a day to day basis, namely Mail,
Calendar, Finance, Reader, Calculator, and the Office apps (in place of the
full suite that I no longer have installed, saving several Gigabytes on my
SSD), and I really struggle to think of any glaring issues that would make
someone so vehemently condemn this entire class of apps.

~~~
MarkSweep
I personally find them to be slow to start. For example, the calculator app
has a loading screen. A loading screen for a calculator! It's usually about
second or half a second, but sometimes it is more. The Photos app has a
similar slowness when opening that is annoying when browsing folders of
photos.

~~~
kyriakos
I used to have the same issue with Windows 8.1 but since Windows 10 they load
almost instantly.

------
lancefisher
And next year when ASP.NET 5 ships, we'll finally be able to use environment
variables for appSettings [1] instead of the hacked up mess that web.config is
right now.

[1]
[http://docs.asp.net/en/latest/fundamentals/configuration.htm...](http://docs.asp.net/en/latest/fundamentals/configuration.html)

~~~
jsudhams
Isn't it bad? Given that only admin/power user can change environment
variable, this will be a issue in shared hosting right?

~~~
frik
Have you ever seen a shared web hoster that used Windows server edition?
Shared hosting usually runs on LAMP.

And server admins/devops won't have a problem. Applications will hopefully use
variable with a prefix, e.g. App123Debug

~~~
jsudhams
Yes, all the time. Azure / EC2 all provide top class windows hosting. But for
low cost shared I am stuck with arvixe and aspdiscount or so... But yeah I
have only windows hosting over 10 years . Gives me everything PHP, python,
.net , MySQL , mssql. I find Linux shared hosting too restricted. especially
with sql server express edition...For me writing .net (actually vb.net) is way
faster personally than even C# I use it all the time , I use c# only when some
function is missing even then I use c# via library and still keep the vb.net.
Though lately vb.net sample codes is very low but easy to convert from c#.
Tried python like it but that 4 whitespace or whatever freaks me out.
Currently on Go and Erlang learning path... but yeah IIS 8.0 excellent
platform for low traffic websites

------
rtpg
always felt like the Windows mechanism of having at least one non-ambiguously
global place to set environment variables to be super useful to deal with
(instead of the ubuntu '/etc/environment/', except when it's '.profile',
except when it's '.pam_environment', except when its '.bashrc')

~~~
whoopdedo
Baseless argument. Windows also splits the environment between the HKLM and
HKCU hives. It just gives you a handy window to edit both at once.

.profile is a login script, not the recommended place for setting variables
although historically it has been because /etc/environment and
~/.pam_environment are relatively recent additions to Linux. (Why didn't
distros adopt the ~/.env though that other Unixes, like AIX, use?) But there
Windows also has the profile login script and I don't know if it's possible to
export environment variables from it but that serves the same purpose of
~/.profile.

So all those things you say are bad about Linux exist on Windows.

~~~
rtpg
I'm not against there being many different hooks in your average linux distro,
but googling 'how to set environment variables in Ubuntu' gives you 20
different answers, with many conflicting statements between them.

------
dlandis
I've wondered why they didn't fix this so many times over the years. Every
time I saw that one inch wide, unresizable text input for the PATH or other
variable, I got that feeling of exasperation you get when you know a company
doesn't listen to its customers. It would have been the easiest thing in the
world to do and yet it took over a decade to do it.

------
galago
I dream that someday I can cut and paste from the command prompt. I mean, I'm
really happy that Microsoft is actually making improvements to parts of
windows that have been needlessly awkward for decades.

~~~
pmorici
You can cut and paste from the command prompt if you go to properties and
check the "Quick Edit Mode" option. It lets you highlight with the left mouse
button and copy by simply clicking the right. w/o quick edit you first have to
select 'Mark' from the context menu then you can highlight text to copy paste.
It has worked this way as long as I can remember.

~~~
baddox
And, bizarrely, the keyboard shortcut to copy marked text is Enter.

~~~
userbinator
Because Ctrl+C was used for "interrupt" long before the concept of copy-paste
came into being. Enter is often used to signify the positive end of an
operation.

~~~
ZenoArrow
If you enable the Ctrl shortcuts for clipboard operations, what shortcut do
you use to stop a running process? Has one been made available?

~~~
ygra
How about Ctrl+C? The meaning is unambiguous: If there is a selection, Ctrl+C
is handled by the console host and copies the selection. If there is no
selection, Ctrl+C is passed on to the running program which then does whatever
it likes with it (i.e. in many cases terminate itself).

~~~
ZenoArrow
Your suggestion makes sense, but my previous question was referring to how
Windows handles this. Do you know if it's possible to assign Ctrl+C to both
operations for the Windows 10 command prompt?

~~~
ygra
That was a description of how Windows handles this. Basically, the current
selection and those capabilities are part of the _console host_. Your
application running in a console window has (to my knowledge) no idea of those
features; it cannot tell whether there is a selection or not or what to do
with it because they happen transparently a layer above your application
(between your application and the window manager, essentially).

So the question you're asking is a bit moot, in a way, considering that the
answer is yes, because that's exactly the way it is. It cannot be any other
way, as far as I can see.

------
cjslep
Hopefully there is no more maximum length that PATH could be. My last
experience was with Windows 7, so maybe a lot has changed since then. Nothing
more annoying than having a custom CMD shortcut that loads a script to add
things to PATH that got truncated otherwise, and maintaining that script as
new programs were installed and wanted to keep adding to PATH.

~~~
userbinator
_as new programs were installed and wanted to keep adding to PATH._

That's more a problem with those programs than anything about the length of an
environment variable.

~~~
HCIdivision17
You're technically correct, but you're really underplaying how goddam
troublesome it can be.

Just a couple days ago, I tried to add a tool to my PATH and it wouldn't stick
because both Intel and Microsoft decided that their utility needed not only
both Program Files and Program Files (x86) for each (doubling their PATH
usage), but Intel also decided to arbitrarily use positively uselessly long
directory names. As in, I actually think it's plausible Intel specifically did
it to screw over PATH usage.

Infuriatingly, the hard PATH limit is _after_ any environment variables have
been expanded, meaning there's no reasonable way to compress the path down.
(Never mind that it also only expands variables less than the string 'PATH'.)
In the end, I used DIR to find what the 8dot3 representation of each repeated
or long directory was.

Now I have enough free characters, but no fracking idea exactly where they
point. It's the sort of crazy that I really thought would have been lic'd by
now.

Edit: I forgot to note that the hard limit is a truncation. So while you can
happily add to the PATH variable in the (now out-dated) dialog, the actual
console won't see all of it. I had moved folders around before my rant above
such that my final PATH exactly ended on "\node\bin". It's sort of a weird
game of PATH golf at this point for me.

~~~
WorldMaker
Did you take a look at those Intel binaries they wanted on the PATH? They are
all diagnostics tools that so far as I know aren't very useful to the average
developer, much less the average consumer. There really doesn't seem to be a
reason for Intel to add them to the PATH, because how often do people make
support calls directly to Intel?

I just remove the Intel folders from my PATH (every time one of their drivers
resmashes them into the PATH).

------
userbinator
Does the "Edit Text..." button still allow access to the old single-string
version? If so, that would be good - nothing worse than making one thing easy
to do, but making something else that used to be easy nearly impossible.

------
ethana
You can't believe how many of the legacy stuff Windows still has. The folder
sharing dialog is still clunky like it's 1998.

~~~
nogridbag
It would be nice if Windows had something equivalent to Airdrop. Then again,
it probably wouldn't help when sharing files been Windows and OS X.

~~~
mcintyre1994
I don't have a windows laptop with bluetooth to test, but doesn't bluetooth
work for this? I haven't used Airdrop though so I might be missing something.
But for example I've used it to send from my mac to android tablet when the
terrible osx/Android file manager program fails to work.

Edit: I think I fat finger downvoted parent, sorry

------
cryptos
I never thought Windows would bring innovation in this dimension! I hated the
PATH dialog for so many years so that I stopped hoping for anything better.

Maybe someday we will have a decent terminal window, too!

~~~
josteink
> Maybe someday we will have a decent terminal window, too!

Have you checked lately? ;)

------
netheril96
Now Mac OS X is the only major operating system without an easy way to modify
environmental variables. Sure, you can edit your `.profile` or `.bashrc` or
`.zhsrc`, but those settings do not carry over to your GUI applications, like
the IDEs I am used to.

~~~
__david__
Which is weird because it _used to_. But ~/.MacOSX/environment.plist (easily
edited in the plist editor) got deprecated and isn't used any more.

Edit: Don't know if you know this, but you can use "launchctl setenv key
value" to set environment variables that get used by GUI programs.
Unfortunately there are 2 _huge_ caveats: 1) it's not persistent so you need
to make something that load them at boot time, and 2) if you load them too
late, they won't be part of the Dock or Finder process and you'll need to
restart those processes to get your custom env vars in there. When you click
something from the Dock, it inherits the environment from the Dock, so it's
important to get your vars into the Dock itself.

I've now grown used to running a script manually at boot time and then doing
"killall Dock" so that when I launch Emacs or XCode I get the right PATH. If
someone has a smoother solution, I'd love to hear it.

------
elchief
You can use 'set' to view envars. Want to see your postgres envars? Type 'set
pg' and it will show anything starting with 'pg'.

You can use 'setx' to permanently set envars too.

You don't need to logout to use them, just restart cmd or whatever program you
use.

~~~
noinsight
Or you can just use PowerShell, which allows you to manipulate all kinds of
things in a filesystem-like manner (PSProviders):

Get-ChildItem env:

New-Item -Path "env:\myvar" -Value "MyValue"

Amongst other things, it works for the registry and even Active Directory.

Edit: for persistency you actually need to use
[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")

~~~
ygra
I answered an interesting SO question on that recently, which asked how to
save and restore the environment in PowerShell. Turns out, the environment
being in a PSDrive helps very much with that because you can treat the
variables just like you treat files:

    
    
        # Save environment
        $savedState = Get-ChildItem Env:
    
        # Restore environment
        Remove-Item Env:*
        $savedState | ForEach-Object { Set-Content Env:$($_.Name) $_.Value }

------
crawrey
I want to know why we are still using environment variables (and paths to a
lesser extent), other than the fact that they are heavily ingrained.

Are there OSs out there that address this solution in a less archaic way?

~~~
a_bonobo
TempleOS has something like a set of environment variables for each task - if
the user asks for a variable and it isn't found, then the parental task's
variables are checked, followed by the next parental task's variables etc.,
all the way up to Adam, which would be like global environment variables.

[http://www.templeos.org/Wb/Doc/Mysteries.html](http://www.templeos.org/Wb/Doc/Mysteries.html)

------
Asbostos
Aren't environment variables kind of a bad thing in Windows? They're global so
installing an application that twiddles with them could break another
application. Isn't that what we had the registry for and now AppData?

Path is a bit different because it's helpful being global so any command
prompt can use it. Though the start menu search bar doesn't seem to so
wouldn't it be better moved to a setting in the command prompt and Powershell
applications themselves?

------
touristtam
Doesn't matter; I use Rapid Environment Editor

[http://www.rapidee.com/en/about](http://www.rapidee.com/en/about)

------
frik
It took them only 25 years to improve the UI (since early days of WinNT 3.1).
Unsexy parts of the OS are rarely touched, e.g. the Windows system font folder
import dialog used to look like a Win16 file open dialog even in Win7.

On the other hand, it was probably by design. Microsoft wanted to promote the
Windows Registry and GUI of Win95/NT4 and made the command prompt (cmd.exe and
other Unix/DOS alike parts) unpopular and not easy to use.

------
0xcde4c3db
I hope this means that somebody also fixes KB329308, which I'm pretty sure was
still around in Windows 7 (unless it already got fixed in 8/8.1) [1]. It's
pretty easy to get bitten by this when setting up Java build tools on Windows.

[1] [https://support.microsoft.com/en-
us/kb/329308](https://support.microsoft.com/en-us/kb/329308)

------
cm2187
The UI was bad, but the length limit is my biggest grief with the path
environment variable. A lot of useless drivers and software feel that they
need to have their own entry and if you have enough software installed in a
box, very bad things will happen when you reach that limit, starting with the
windows UI falling apart.

------
snarfy
And each entry is still limited to MAX_PATH.

------
NicoJuicy
I don't know why everyone says copy paste from/to an text-editor... I copied a
path into my clipboard and wrote ;{past-shortcut} and click ok. And the path
was added.

In terms of developer UX, i now have to do 1 step more (click add button,
paste the string, click ok, click ok).

PS. It was rare that i actually had to change a path

------
zongitsrinzler
It's nice that MS is picking up the slack. Pity that all sane developers have
already moved to OSX or Linux.

~~~
runholm
That's not true at all. In the corporate world Windows is still the default
because of many the tools used to make large organisations flow are available
only on Windows. OSX and Linux is used a lot as well, but it's most common in
small organisations and new "hipper" companies.

------
pix64
Now if only you could change the Path without logging out and back in.

~~~
Too
You can. At least for cmd.exe you just have to open a new console, but no need
to fully log out and in again.

~~~
ygra
This works for any application started by Explorer (which also means the task
bar and start menu). Windows broadcasts a message that the environment has
changed and Explorer listens and updates its environment accordingly.

