Path environment variables and the registry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • beaker

    #1

    Path environment variables and the registry


    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.Curren tUser.OpenSubKe y("Environment" , True)
    Dim s As String = CType(regKey.Ge tValue("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.Get Variables("path ") from within my
    application).

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

    Many thanks,

    Gary
  • kHSw

    #2
    Re: Path environment variables and the registry

    Have a look at the article I mentioned in my previous reply:


    " 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_SETTINGCHANG E 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. "


    Comment

    • beaker

      #3
      Re: Path environment variables and the registry

      kHSw wrote:[color=blue]
      > 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_SETTINGCHANG E 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. "
      >
      >[/color]

      Aah, it all becomes clear! Thanks for that.

      Comment

      Working...