Changed PATH in Registry but its not changed in Environment

Just starting out? Need help? Post your questions and find answers here.
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Changed PATH in Registry but its not changed in Environment

Post by Straker »

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.
Image Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Changed PATH in Registry but its not changed in Environm

Post by srod »

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.
I may look like a mule, but I'm not a complete ass.
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Re: Changed PATH in Registry but its not changed in Environm

Post by Straker »

Thanks srod! You are the man!

Here's what seems to work:

Code: Select all

*lResult = 0
Debug SendMessageTimeout_(#HWND_BROADCAST,#WM_SETTINGCHANGE,0,"Environment",2,1000,*lResult)
Debug *lResult
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!
Image Image
Post Reply