title: Why doesn't SendMessageTimeout update the environment variables?
body: <p>Question: I have an installer, and it installs some native dll's along with the program.
  The dll's are in a separate folder, which I added to the path environment variable.</p>
  
  <p>That was done successfully, and the variable shows up in path if I check the windows system settings.</p>
  
  <p>However, if I start the command line program/service, it says dll's not found...</p>
  
  <p>I check the environment variable path with the set command, and my folder is not in there.</p>
  
  <p>If I do</p>
  
  <pre><code>SET path = %path%;my/folder/here/
  </code></pre>
  
  <p>And start my program after that, then it works.</p>
  
  <p>According to <a href="http://support.microsoft.com/?kbid=104011" rel="noreferrer">this MS KB article</a> this is because the computer would need to be restarted.</p>
  
  <p>unless I do</p>
  
  <pre><code>SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &amp;dwReturnValue);            
  </code></pre>
  
  <p>Now I did just that, using the below code, but the error message persists. My folder in %path% is correctly spelled, I checked that.</p>
  
  <p>What am I doing wrong ?</p>
  
  <pre><code>' http://www.pinvoke.net/default.aspx/Enums/SendMessageTimeoutFlags.html '
  &lt;Flags()&gt; _
  Public Enum SendMessageTimeoutFlags
      SMTO_NORMAL = 0
      SMTO_BLOCK = 1
      SMTO_ABORTIFHUNG = 2
      SMTO_NOTIMEOUTIFNOTHUNG = 8
  End Enum    
  
  ' http://ghouston.blogspot.com/2005/08/how-to-create-and-change-environment.html '
  Public Const HWND_BROADCAST As Integer = &amp;HFFFF
  Public Const WM_SETTINGCHANGE As Integer = &amp;H1A    
  
  ' http://pinvoke.net/default.aspx/user32.SendMessageTimeout '
  &lt;System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)&gt; _
  Public Shared Function SendMessageTimeout(ByVal windowHandle As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal flags As SendMessageTimeoutFlags, ByVal timeout As Integer, ByRef result As IntPtr) As IntPtr
  End Function    
  
  ' http://support.microsoft.com/?kbid=104011 '
  ' http://blog.jtbworld.com/2005/11/set-environment-variable-using-vbnet.html '
  Sub UpdatePath()
      Dim result As Integer
      ' SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM) "Environment", SMTO_ABORTIFHUNG,5000, &amp;dwReturnValue); '   
  
      ' CType("Environment", System.IntPtr) '
      Dim s As String = New String("Environment")
      Dim ptr As IntPtr = Runtime.InteropServices.Marshal.StringToHGlobalUni(s)
  
      'SendMessageTimeout(CType(HWND_BROADCAST, System.IntPtr), WM_SETTINGCHANGE, 0, ptr, SendMessageTimeoutFlags.SMTO_BLOCK Or SendMessageTimeoutFlags.SMTO_ABORTIFHUNG Or SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 5000, result) '
      SendMessageTimeout(CType(HWND_BROADCAST, System.IntPtr), WM_SETTINGCHANGE, 0, ptr, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 5000, result)
  End Sub
  </code></pre>