You are here

Environment variable

8 posts / 0 new
Last post
fgagnon
Offline
Last seen: 2 years 2 months ago
Joined: 2019-04-12 08:17
Environment variable

Would it be possible to add an option in the platform to allow it to re-read the system's environment variables and pass them to an app upon launch ? We use the PortableApps platform where the environment variables do change a lot and it is counterproductive to have to stop/start the platform every time the environment gets modified.

John T. Haller
John T. Haller's picture
Offline
Last seen: 2 hours 54 min ago
AdminDeveloperModerator
Joined: 2005-11-28 22:21
Bit Unusual

We don't do anything special to get environment variables. Windows provides them to each process as they start and then they're available to that process. Our platform process automatically passed them along to any processes it starts. This is the standard way processes in Windows work. Is there some specific reason you're updating environment variables regularly? Perhaps something that could be handled another way?

Sometimes, the impossible can become possible, if you're awesome!

fgagnon
Offline
Last seen: 2 years 2 months ago
Joined: 2019-04-12 08:17
Reason to change environment variables

We use PortableApps platform in a work environment where we do software development and we often change environment variables for different reasons (e.g. to declare a new version of a build dependency). We end up with a system environment that changes regularly. The issue here with the platform is that it must be killed/restarted to get the new environment variables every time they are changed.

John T. Haller
John T. Haller's picture
Offline
Last seen: 2 hours 54 min ago
AdminDeveloperModerator
Joined: 2005-11-28 22:21
Unusual, Undocumented

I've found no documentation or examples of reloading environment variables on a WM_SETTINGCHANGE to then pass on to underlying processes from the parent process using Delphi. It's a very unusual request. I've only come across it in bug reports/feature requests in relation to IDEs and text editors and most of them seem to be of the 'restart to get the changes variables' variety.

If anyone is aware of a way to do this without impacting other stuff, I'd implement it.

Sometimes, the impossible can become possible, if you're awesome!

fgagnon
Offline
Last seen: 2 years 2 months ago
Joined: 2019-04-12 08:17
Updating environment variables

I am no Delphi coder but after a bit of research, I've found this post on how to catch WM_SETTINGCHANGE using Delphi:
http://www.delphigroups.info/2/59/480668.html

Upon catching the message, the PortableApps platform should delete all its current environment variables then read all the environment variables located in the registry at the following locations:
System environment variables: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
User environment vaiables: HKEY_CURRENT_USER\Environment

Once the environment variables have been read from the registry, they shall be applied to the PortableApps platform to be latter passer to child processes.

See this post on how to manage environment variables for the current process in Delphi:
http://delphidabbler.com/articles?article=6

Thanks for your help !

John T. Haller
John T. Haller's picture
Offline
Last seen: 2 hours 54 min ago
AdminDeveloperModerator
Joined: 2005-11-28 22:21
Breaks Soft Setting, Gets Stale Variables

The problem is this breaks soft setting environment variables before launching the PA.c Platform, which I know some users do. Catching WM_SETTINGSCHANGE is trivial. Additionally, the last link will get the stale environment variables passed to our process when it was started, it won't get them from the registry. You have to loop through everything in both registry keys and call a set for each variable to 'refresh' them from the registry. But, of course, you lose anything that was soft set by your own parent process.

Sometimes, the impossible can become possible, if you're awesome!

fgagnon
Offline
Last seen: 2 years 2 months ago
Joined: 2019-04-12 08:17
Option

Why not make this optional then to reload then environment variables from the registry upon reception of WM_SETTINGSCHANGE ?

deliverence
Offline
Last seen: 2 years 1 month ago
Joined: 2019-07-22 08:22
Yeah we get to stop and start

Yeah we get to stop and start due to this often as well, can be bothersome but at least it works.

Log in or register to post comments