Is there a way to set the environment path programmatically in C++ on Windows?

后端 未结 5 1260
野的像风
野的像风 2020-12-08 16:24

Is there a way to set the global windows path environment variable programmatically (C++)?

As far as I can see, putenv sets it only for the current application.

5条回答
  •  一个人的身影
    2020-12-08 16:55

    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.

提交回复
热议问题