Tutorial :Set environment variables from Delphi (Win32)



Question:

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.


Solution:1

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


Solution:2

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »