从Delphi(Win32)设置环境变量

时间:2021-07-29 11:53:51

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?

我正在尝试从我的delphi应用程序中设置系统范围的环境变量。文档说要将注册表项添加到HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment,然后广播WM_SETTINGCHANGE消息。有谁知道如何广播这条消息?

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

PS。我正在尝试在控制台应用程序中执行此操作。

2 个解决方案

#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:

Embarcadero开发者网络中还有一个主题涉及此问题,并提供用于发送消息的示例代码。作者使用MSDN doc for WM_SETTINGCHANGE中建议的SendMessageTimeout:

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

#2


Call SendMessage. Use HWnd_Broadcast as the target window.

调用SendMessage。使用HWnd_Broadcast作为目标窗口。

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

更好的选择可能是SendNotifyMessage,它不等待所有收件人返回。

#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:

Embarcadero开发者网络中还有一个主题涉及此问题,并提供用于发送消息的示例代码。作者使用MSDN doc for WM_SETTINGCHANGE中建议的SendMessageTimeout:

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

#2


Call SendMessage. Use HWnd_Broadcast as the target window.

调用SendMessage。使用HWnd_Broadcast作为目标窗口。

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

更好的选择可能是SendNotifyMessage,它不等待所有收件人返回。