I recently came across something similar, and broadcasting the message is the correct way, as described in this kb (and parapura):
http://support.microsoft.com/kb/104011
however, I would suggest putting _T () around the "environment" (or possibly "L") to make sure you are passing in the correct line (ansi or wide). eg:
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) _T("Environment"), SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
I used the above in a command line application. without _T (), sending the message is successful, but my system never receives updates to the environment variable.
btw, the 'setx' command line probably uses the same mechanism to update environment variables. In addition, I use this in the atl dll.
source share