如何在 C++ 中添加环境变量?

2022-01-16 00:00:00 windows environment-variables c++

有什么方法可以通过 C++ 在 Windows 中添加环境变量?

Is there any way I can add environment variable in Windows via C++?

必须在我的电脑->属性->高级->环境变量"中添加

They have to be added in "My computer->properties->advanced->environment variables"

谢谢

推荐答案

来自 MSDN :

以编程方式添加或修改系统环境变量,添加它们到HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession ManagerEnvironment 注册表项,然后广播 WM_SETTINGCHANGE 消息lParam 设置为字符串环境".这允许应用程序,例如外壳,以拿起你的更新...

To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession ManagerEnvironment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates ...

相关文章