[VB.Net WinForms] Proxy Switcher

access_time Monday, February 24, 2014 11:12 pm
account_circle Andy Boot

‘ Description
‘ ————
‘ Very simple application to switch the Internet Explorer proxy settings on or off at a click of a button.
‘ Tested with Windows XP – Windows 7

‘ Traditionally run on a laptop in a business environment using a proxy server. Allows the user to browse
‘ the internet within a non-business wireless network without the need of connecting to a VPN connection.

Imports Microsoft.Win32

Public Class frmMain

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim regKey As RegistryKey
Dim regKey2 As RegistryKey
Dim ver As Decimal

regKey = Registry.CurrentUser.OpenSubKey(“SoftwareMicrosoftWindowsCurrentVersionInternet Settings”, True)
regKey2 = Registry.CurrentUser.OpenSubKey(“SoftwareMicrosoftInternet ExplorerMain”, True)

ver = regKey.GetValue(“ProxyEnable”)

If Button1.Text = “Switch Proxy OFF” Then
regKey.SetValue(“ProxyEnable”, “0”, RegistryValueKind.DWord)
regKey2.SetValue(“Start Page”, “http://www.somewhere.com”)
Button1.Text = “Switch Proxy ON”
TextBox1.Text = “Internet Explorer wireless internet access enabled.”

Else
regKey.SetValue(“ProxyEnable”, “1”, RegistryValueKind.DWord)
regKey.SetValue(“ProxyServer”, “1.1.1.1:3128”)
regKey2.SetValue(“Start Page”, “http://intranet”)
Button1.Text = “Switch Proxy OFF”
TextBox1.Text = “Internet Explorer WILL now use the proxy server to access the internet.”
End If
regKey.Close()

MsgBox(“You are required to close Internet Explorer and open it again for the settings to be applied.”)
End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim regKey As RegistryKey
Dim ver As Decimal

regKey = Registry.CurrentUser.OpenSubKey(“SoftwareMicrosoftWindowsCurrentVersionInternet Settings”, True)
ver = regKey.GetValue(“ProxyEnable”)

If ver = 0 Then
Button1.Text = “Switch Proxy ON”
TextBox1.Text = “Internet Explorer wireless internet access enabled.”
Else
Button1.Text = “Switch Proxy OFF”
TextBox1.Text = “Internet Explorer WILL now use the proxy server to access the internet.”
End If
regKey.Close()
End Sub
End Class