Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Class ProxyChanger
<DllImport("wininet.dll")> _
Public Shared Function InternetSetOption(hInternet As IntPtr, dwOption As Integer, lpBuffer As IntPtr, dwBufferLength As Integer) As Boolean
End Function
Public Const INTERNET_OPTION_SETTINGS_CHANGED As Integer = 39
Public Const INTERNET_OPTION_REFRESH As Integer = 37
Public Function SetProxy(Server As String, Port As String) As Boolean
Dim RKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
RKey.SetValue("ProxyServer", Server + ":" + Port)
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0)
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0)
RKey.SetValue("ProxyEnable", 1)
Dim IsEnabled As Boolean = False
If Not RKey.GetValue("ProxyEnable") = 0 Then
IsEnabled = True
End If
Return IsEnabled
End Function
Public Function DisableProxy() As Boolean
Dim RKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
RKey.SetValue("ProxyEnable", 0)
Dim Result As Boolean = False
If RKey.GetValue("ProxyEnable") = 0 Then
Result = True
End If
Return Result
End Function
Public Function EnableProxy() As Boolean
Dim RKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
RKey.SetValue("ProxyEnable", 1)
Dim Result As Boolean = False
If Not RKey.GetValue("ProxyEnable") = 0 Then
Result = True
End If
Return Result
End Function
Public Function IsProxyEnabled() As Boolean
Dim RKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
Dim Result As Boolean = True
If RKey.GetValue("ProxyEnable") = 0 Then
Result = False
End If
Return Result
End Function
End Class
Create a new instance of this class from your program and call the functions to Set / Disable proxy: