Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

VB.Net: Programaticaly changing the Ignore addresses in the proxy settings

From Wiki

Jump to: navigation, search

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

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <IgnoreAddresses>
  3.   <Address>10.0.0.185</Address>
  4.   <Address>10.0.0.28</Address>
  5. </IgnoreAddresses>

And this is the class.

  1. Imports Microsoft.Win32
  2. Imports System.Xml
  3.  
  4. Namespace ProxySettings
  5.     ''' <summary>
  6.     '''
  7.     ''' </summary>
  8.     ''' <remarks></remarks>
  9.     Public Class ProxyOverrides
  10.  
  11. #Region " Constants "
  12.         ''' <summary>
  13.         '''
  14.         ''' </summary>
  15.         ''' <remarks></remarks>
  16.         Const regProxy As String = "Software\microsoft\windows\currentversion\internet settings"
  17.         ''' <summary>
  18.         '''
  19.         ''' </summary>
  20.         ''' <remarks></remarks>
  21.         Const regValue As String = "proxyoverride"
  22.         ''' <summary>
  23.         '''
  24.         ''' </summary>
  25.         ''' <remarks></remarks>
  26.         Const xmlFile As String = "ProxySettings\IgnoreIPAddresses.xml"
  27. #End Region
  28.  
  29. #Region " Private members "
  30.  
  31. #End Region
  32.  
  33. #Region " Public methods "
  34.         ''' <summary>
  35.         '''
  36.         ''' </summary>
  37.         ''' <remarks></remarks>
  38.         Public Shared Sub CheckProxyOverrides()
  39.             Dim _ProxyOverride As String
  40.             Dim _Key As RegistryKey
  41.             Dim _ToAdd As String = ""
  42.             Dim _Seperator As String = ""
  43.             Impersonation.Impersonation.ImpersonateAdministrator(True)
  44.             _Key = Registry.CurrentUser.OpenSubKey(regProxy, True)
  45.             _ProxyOverride = _Key.GetValue(regValue).ToString
  46.             If Not _ProxyOverride = "<local>" Then
  47.                 _Seperator = ";"
  48.             End If
  49.             Dim _doc As New XmlDocument
  50.             _doc.Load(xmlFile)
  51.             Dim _addresses As XmlNodeList = _doc.GetElementsByTagName("Address")
  52.             For i As Integer = 0 To _addresses.Count - 1
  53.                 If _ProxyOverride.IndexOf(_addresses(i).InnerText) = -1 Then
  54.                     _ToAdd &= _Seperator & _addresses(i).InnerText
  55.                     _Seperator = ";"
  56.                 End If
  57.             Next
  58.             If Not String.IsNullOrEmpty(_ToAdd) Then
  59.                 _Key.SetValue(regValue, _ProxyOverride & _ToAdd)
  60.             End If
  61.             Impersonation.Impersonation.ImpersonateAdministrator(False)
  62.         End Sub
  63. #End Region
  64.  
  65.     End Class
  66. End Namespace

387 Rating: 1.3/5 (3 votes cast)