Hi All.
I am writing an app which requires the addition of new directories to the environmental PATH variable.
So after successful creation of the new directories, I add the new directories to the registry PATH value at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.
But this new PATH setting does not reflect in the current environment. I have to reboot in order to get my changes recognized.
But if I add the directories to the PATH using Control Panel, the settings are saved to the Registry AND the current environment reflects the change. So somehow, the Control Panel is notifying the current environment of the change and the current environment updates its variables in memory accordingly.
What am I missing here? Is there a Windows API call I need to make to do this?
I am using Win XP SP3.
Thanks in advance for any help.
Changed PATH in Registry but its not changed in Environment
Re: Changed PATH in Registry but its not changed in Environm
A bit of a guess, but it might be that you have to broadcast an appropriate #WM_SETTINGCHANGE message to all top-level windows after you modify the registry. When you broadcast the message you can point to the registry key you have modified etc.
**EDIT : yes, found some c# code which adds to the system path and indeed it broadcasts a #WM_SETTINGCHANGE message.
http://bytes.com/topic/c-sharp/answers/ ... t-variable
Note the use of SendMessageTimeout_() when sending the broadcast.
**EDIT : yes, found some c# code which adds to the system path and indeed it broadcasts a #WM_SETTINGCHANGE message.

http://bytes.com/topic/c-sharp/answers/ ... t-variable
Note the use of SendMessageTimeout_() when sending the broadcast.
I may look like a mule, but I'm not a complete ass.
Re: Changed PATH in Registry but its not changed in Environm
Thanks srod! You are the man!
Here's what seems to work:
If you have a better suggestion for the parameters, let me know, but this seems to work.
More info here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Thanks again!
Here's what seems to work:
Code: Select all
*lResult = 0
Debug SendMessageTimeout_(#HWND_BROADCAST,#WM_SETTINGCHANGE,0,"Environment",2,1000,*lResult)
Debug *lResult
More info here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Thanks again!