我在 IE 中重新加载代理设置时遇到问题。我想在不重新启动 IE 和 Chrome 的情况下重新加载代理选项。我注意到 InternetSetOption 返回 false。
定义:
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
和内部功能:
InternetSetOption(vbNull, INTERNET_OPTION_SETTINGS_CHANGED, vbNull, 0)
InternetSetOption(vbNull, INTERNET_OPTION_REFRESH, vbNull, 0)
这是整个功能:
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