Path environment variables and the registry

B

beaker

Hi,

This may be slightly OT, but as I'm using VB.NET I'll ask anyway...

I'm trying to update my path using the following code to tweak the registry


Dim regKey As RegistryKey
regKey = Registry.CurrentUser.OpenSubKey("Environment", True)
Dim s As String = CType(regKey.GetValue("Path"), String)
s = s & ";" & TextBox1.Text
regKey.SetValue("Path", s)
regKey.Close()

Which seems to work, in that the registry is updated correctly (checked
with regedit) and my user path seems to have been updated (checked with
right click on my computer, advanced, environment variables...)

My problem is that the actual path doesn't seem to have been updated in
practice (checked by typing 'path' on command line - new folder not
added, and using Environment.GetVariables("path") from within my
application).

Why does this discrepancy occur, and how do I fix it?

Many thanks,

Gary
 
K

kHSw

Have a look at the article I mentioned in my previous reply:
http://support.microsoft.com/kb/q104011/

" However, note that modifications to the environment variables do not
result in immediate change. For example, if you start another Command Prompt
after making the changes, the environment variables will reflect the
previous (not the current) values. The changes do not take effect until you
log off and then log back on.

To effect these changes without having to log off, broadcast a
WM_SETTINGCHANGE message to all windows in the system, so that any
interested applications (such as Windows Explorer, Program Manager, Task
Manager, Control Panel, and so forth) can perform an update. "
 
B

beaker

kHSw said:
Have a look at the article I mentioned in my previous reply:
http://support.microsoft.com/kb/q104011/

" However, note that modifications to the environment variables do not
result in immediate change. For example, if you start another Command Prompt
after making the changes, the environment variables will reflect the
previous (not the current) values. The changes do not take effect until you
log off and then log back on.

To effect these changes without having to log off, broadcast a
WM_SETTINGCHANGE message to all windows in the system, so that any
interested applications (such as Windows Explorer, Program Manager, Task
Manager, Control Panel, and so forth) can perform an update. "

Aah, it all becomes clear! Thanks for that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top