我在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
答案 0 :(得分:1)
您需要将vbnulls更改为IntPtr.Zero。这应该可以解决问题。
Imports System
Imports System.Runtime.InteropServices
Namespace UpdateProxy
Friend Class Program
Public Shared Declare Auto Function InternetSetOption Lib "wininet.dll" (hInternet As IntPtr, dwOption As Integer, lpBuffer As IntPtr, dwBufferLength As Integer) As Boolean
Private Shared Sub Main(args As String())
Program.InternetSetOption(IntPtr.Zero, 39, IntPtr.Zero, 0)
Program.InternetSetOption(IntPtr.Zero, 37, IntPtr.Zero, 0)
End Sub
End Class
End Namespace
这个简单的程序将使用注册表中的代理设置更新IE的运行实例。