0

Exactly what it says. I can set per-user environment variables, either from Windows > type "Path", or using RegEdit, or even from a Python script.

But if I run an application (e.g. from Launchy, or launch it from Chrome), it won't pick up the new variables. I've got to start a new cmd or Windows Explorer (I think) to get the new values.

Now, obviously I can set them on a per-use basis, but I want to set them globally for my account, and also for whatever process I happen to be using at the time. Is this possible? And is it possible (or easier) to do from a Python script?

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • Take a look at [this question](http://stackoverflow.com/questions/205064/is-there-a-way-to-change-another-processs-environment-variables). It is about Unix, but there is a comment saying that it work in Windows with cygwin. If that's the case, you might be able to do that with any debugger. – rodrigo Feb 26 '13 at 21:59
  • @rodrigo That's pretty sweet, but it looks like it only works on processes launched from cygwin. According to the Windows documentation I've been seeing, they don't let you control other processes, only broadcasting messages that the other application then is responsible for listening to/responding. Bah! – Wayne Werner Feb 26 '13 at 22:18
  • One of the comments say "It even works on Windows using cygwin, for processes that are not compiled using cygwin!". My guess is that you can do what you want _simply_ by running a remote thread that calls `putenv()` (or `SetEnvironmentVariable()`) with the appropriate arguments. And that's precisely what the debugger does. You can conceivable write a tool that does that, but not in Python! – rodrigo Feb 26 '13 at 22:58

1 Answers1

4

If you set an environment variable in the registry (or via the System Properties > Advanced > Environment Variables UI), it will be global and persistent for every process launched from the top level context created after the variable was set. Shells and contexts initialized before your change will not pick up those changes unless you explicitly merge the values from the registry with the existing values in that context though. Each context inherits the environment of its parent, but after that point, changes to the parent or child environments do not propagate in either direction. Contexts created at the top level get their environment from the registry.

Silas Ray
  • 25,682
  • 5
  • 48
  • 63
  • 1
    Is there a list/site anywhere that contains the different methods that create **new** contexts? And is there any way to trigger creating the new context from some other context? – Wayne Werner Feb 26 '13 at 21:43