feihtthief
feihtthief

Reputation: 7063

Set environment variables from Delphi (Win32)

I'm trying to set a system wide environment variable from within my delphi application. The Documentation says to add a registry key to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and then broadcast a WM_SETTINGCHANGE message. Anyone know how to Broadcast this message?

PS. I'm trying to do this in a console application.

Upvotes: 3

Views: 4551

Answers (2)

Heinrich Ulbricht
Heinrich Ulbricht

Reputation: 10372

There is also a topic in the Embarcadero Developer Network covering this issue and providing sample code for sending the message. The author uses SendMessageTimeout as recommended in the MSDN doc for WM_SETTINGCHANGE:

http://edn.embarcadero.com/article/28254

Upvotes: 1

Rob Kennedy
Rob Kennedy

Reputation: 163247

Call SendMessage. Use HWnd_Broadcast as the target window.

A better option may be SendNotifyMessage, which doesn't wait for all the recipients to return.

Upvotes: 5

Related Questions