Link to home
Start Free TrialLog in
Avatar of DColin
DColinFlag for Thailand

asked on

Set Internet Explorer proxy settings from VB.Net code

Hi Experts,

How do I turn on/off the Internet Explorer Proxy settings from my VB.Net code.
Avatar of mahadevan_v
mahadevan_v

Public Sub EnableProxy()
        If objHost.DirectConnection = False Then
            Dim regKey As RegistryKey

            regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)

            regKey.SetValue("ProxyEnable", True, RegistryValueKind.DWord)
            regKey.SetValue("ProxyServer", objHost.ProxyAddress.ToString + ":" + objHost.ProxyPort.ToString, RegistryValueKind.String)

            If objHost.BypassLocal Then
                regKey.SetValue("ProxyOverride", "<local>", RegistryValueKind.String)
            Else
                regKey.DeleteValue("ProxyOverride", False)
            End If

            regKey.Close()
        Else
            MessageBox.Show("Network Switcher is currently not configured to use a proxy server. " + ControlChars.CrLf + _
                            "Please open Network Switcher settings dialog and configure the proxy server.", "Missing proxy settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub

    Public Sub DisableProxy()
        Dim regKey As RegistryKey

        regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)

        regKey.SetValue("ProxyEnable", False, RegistryValueKind.DWord)

        regKey.Close()
    End Sub

RESTART THE IE Instance :)
Avatar of DColin

ASKER

Hi mahadevan_v

When I use your code I get an 'objHost not declared' error. I notice from your code that you do not declare the objHost object. Do I need to import a namespace?
ASKER CERTIFIED SOLUTION
Avatar of Ledigimate
Ledigimate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial