On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote:
Any solutions that people know of?

You can't from an exe, it is a limitation of the operating system (same on Linux btw, environment variable inheritance is always from parent to child, never from child to parent). The reason batch files can do it is that they don't run in a separate process, they just run a batch of commands inside the shell itself.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009%28v=vs.85%29.aspx

"Altering the environment variables of a child process during process creation is the only way one process can directly change the environment variables of another process. A process can never directly change the environment variables of another process that is not a child of that process."

If you're an administrator, you could poke the system-wide variables in the registry and tell the processes to reload them: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682653%28v=vs.85%29.aspx

but of course, changing system-wide registry entries affects way more than just your parent shell!



If you need to change a parent shell variable, the only way is to do it from a batch file. You could perhaps run a .bat which sets the variable and calls your exe to help it do some work.

Reply via email to