1

I use Delphi 10 Seattle on a Windows7 64bit machine.

Here is the problem:

In order to create a test environment for my software, I created a little application that adds environment variables into the Windows registry under

HKEY_CURRENT_USER\Environment 

I use these variables in the search paths of my packages and the main project, in order to be able to also commit project settings into source control and to easily switch from production to test branches etc ...

Now, the problem is, that after creating the environment variable, Delphi does not update its "internal System Variable store" under

Tools --> Options --> Environment Variables 

and the project does not compile.

Even restarting Delphi did not bring the desired effect. I had to reboot Windows completely, in order to make it work.

is there a way to update the System Variables in Delphi within my application? Am I missing something else?

Thanks a lot!

6
  • Out of curiosity, try killing and restarting explorer.exe - maybe restarting the shell will force a refresh. Commented Jun 2, 2016 at 13:39
  • 4
    See How do you add a Windows environment variable without rebooting?. Commented Jun 2, 2016 at 13:45
  • You should read the documentation for environment variables, which tells you how to do this. It feels rather as though you are trying to reverse engineer this. Did you look for the documentation? Commented Jun 2, 2016 at 14:37
  • Thank you alltogether. To be honest, searching for delphi embarcadero documentation is quite tedious. I always end up using google or directly go to stackoverflow.com. In this case, I found for instance SetEnvironmentVariable() but this only sets the variable at runtime for the running process. What I need is a true system variable which lives on after I created it. Commented Jun 2, 2016 at 17:06
  • 2
    When you were taken to Stack Overflow, did you read the answers? Try this one: stackoverflow.com/q/5898131/33732. Note that the solution is two steps, not just one. (Found by searching Google for "windows permanently set environment variable.") Commented Jun 2, 2016 at 17:42

1 Answer 1

6

I am doing something similar in my Path Compressor described in this blog post. The relevant method is this one:

procedure TPathCompressor.NotifyChanges; { Sending a WM_SETTINGCHANGE message to all top level windows. Otherwise the new environment variables will only be visible after logoff/logon. } begin {$IFDEF DEBUG} Exit; {$ENDIF} SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, NativeInt(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, nil); end; 
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly doing what it is supposed to do:) Thank you Uwe and thanks to all the others as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.