Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
VB.Net: Programaticaly changing the Ignore addresses in the proxy settings
From Wiki
Sometimes you want to add a number of ignore addresses to your proxysettings.
This method uses the method discussed here VB.Net: Impersonating an administrator.
First you have to create an xml file like this one
- <?xml version="1.0" encoding="utf-8" ?>
- <IgnoreAddresses>
- <Address>10.0.0.185</Address>
- <Address>10.0.0.28</Address>
- </IgnoreAddresses>
And this is the class.
- Imports Microsoft.Win32
- Imports System.Xml
- Namespace ProxySettings
- ''' <summary>
- '''
- ''' </summary>
- ''' <remarks></remarks>
- Public Class ProxyOverrides
- #Region " Constants "
- ''' <summary>
- '''
- ''' </summary>
- ''' <remarks></remarks>
- Const regProxy As String = "Software\microsoft\windows\currentversion\internet settings"
- ''' <summary>
- '''
- ''' </summary>
- ''' <remarks></remarks>
- Const regValue As String = "proxyoverride"
- ''' <summary>
- '''
- ''' </summary>
- ''' <remarks></remarks>
- Const xmlFile As String = "ProxySettings\IgnoreIPAddresses.xml"
- #End Region
- #Region " Private members "
- #End Region
- #Region " Public methods "
- ''' <summary>
- '''
- ''' </summary>
- ''' <remarks></remarks>
- Public Shared Sub CheckProxyOverrides()
- Dim _ProxyOverride As String
- Dim _Key As RegistryKey
- Dim _ToAdd As String = ""
- Dim _Seperator As String = ""
- Impersonation.Impersonation.ImpersonateAdministrator(True)
- _Key = Registry.CurrentUser.OpenSubKey(regProxy, True)
- _ProxyOverride = _Key.GetValue(regValue).ToString
- If Not _ProxyOverride = "<local>" Then
- _Seperator = ";"
- End If
- Dim _doc As New XmlDocument
- _doc.Load(xmlFile)
- Dim _addresses As XmlNodeList = _doc.GetElementsByTagName("Address")
- For i As Integer = 0 To _addresses.Count - 1
- If _ProxyOverride.IndexOf(_addresses(i).InnerText) = -1 Then
- _ToAdd &= _Seperator & _addresses(i).InnerText
- _Seperator = ";"
- End If
- Next
- If Not String.IsNullOrEmpty(_ToAdd) Then
- _Key.SetValue(regValue, _ProxyOverride & _ToAdd)
- End If
- Impersonation.Impersonation.ImpersonateAdministrator(False)
- End Sub
- #End Region
- End Class
- End Namespace



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.