title: Visual Basic InternetSetOption
body: <p>I have got problem with reloading proxy settings in IE. I want to reload proxy options without restarting IE and Chrome. I've notice that InternetSetOption returns false. </p>
  
  <p>Definitions:</p>
  
  <pre><code>Private Declare Auto Function InternetSetOption Lib "wininet.dll" (ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
  
  Private Const INTERNET_OPTION_REFRESH As Long = 37
  Private Const INTERNET_OPTION_SETTINGS_CHANGED As Long = 39
  </code></pre>
  
  <p>And inside function:</p>
  
  <pre><code>InternetSetOption(vbNull, INTERNET_OPTION_SETTINGS_CHANGED, vbNull, 0)
  InternetSetOption(vbNull, INTERNET_OPTION_REFRESH, vbNull, 0)
  </code></pre>
  
  <p>Here is whole function:</p>
  
  <pre><code>Public Sub SetProxy() 'ByVal ServerName As String, ByVal port As Integer
      Dim regkey1 As RegistryKey
      regkey1 = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", RegistryKeyPermissionCheck.Default)
      regkey1.SetValue("ProxyServer", "ftp=10.8.0.1:808;http=10.8.0.1:808;https=10.8.0.1:808;socks=10.8.0.1:1080", RegistryValueKind.Unknown)
      regkey1.SetValue("ProxyEnable", True, RegistryValueKind.DWord)
      regkey1.Close()
  
      Dim regKey7 As RegistryKey
      regKey7 = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", RegistryKeyPermissionCheck.Default)
  
  
      Dim regKe As Object = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", True).GetValue("DefaultConnectionSettings")
      If regKe Is Nothing Then
      Else
          regKey7.DeleteValue("DefaultConnectionSettings")
      End If
  
      Dim regk As Object = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", True).GetValue("SavedLegacySettings")
      If regk Is Nothing Then
      Else
          regKey7.DeleteValue("SavedLegacySettings")
      End If
  
      regKey7.Close()
  
      InternetSetOption(vbNull, INTERNET_OPTION_SETTINGS_CHANGED, vbNull, 0)
      InternetSetOption(vbNull, INTERNET_OPTION_REFRESH, vbNull, 0)
  
      Label1.Text = "Connected to Disa's Proxy Server"
      Label1.ForeColor = Color.Green
  
  
  
  End Sub
  </code></pre>