Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
Changing directly in the registry (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) is also an option though I would prefer API methods if there are?

like image 313
LK. Avatar asked Feb 10 '09 11:02

LK.


1 Answers

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.

like image 127
Assaf Lavie Avatar answered Sep 18 '22 13:09

Assaf Lavie