gpt4 book ai didi

c++ - 有没有办法在 Windows 上的 C++ 中以编程方式设置环境路径?

转载 作者:IT老高 更新时间:2023-10-28 22:08:14 25 4
gpt4 key购买 nike

有没有办法以编程方式(C++)设置全局windows路径环境变量?

据我所知,putenv 只为当前应用程序设置它。
直接在注册表中更改 (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) 也是一种选择,但如果有的话我更喜欢 API 方法?

最佳答案

MSDN Says :

Calling SetEnvironmentVariable has no effect on the system environment variables. To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment 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. Note that the values of the environment variables listed in this key are limited to 1024 characters.

关于c++ - 有没有办法在 Windows 上的 C++ 中以编程方式设置环境路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/531998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com