Solved

Programmatically change proxy settings

Posted on 2006-06-22
6
579 Views
Last Modified: 2012-06-27
Hi experts,

How can I programmatically switch the Lan settings between Automatically detect settings, and use proxy settings (Proxy 8080)?
0
Comment
Question by:jonastovsen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16964194
The best question I can ask right now is, "Why?"

Bob
0
 

Author Comment

by:jonastovsen
ID: 16964292
Because some of the users are connected through a VPN connection, and som are not. I want to give the user the opportunity to easily swith between Proxy and not.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16964327
Now I understand ;)

Here is a C# example:

SwitchNetConfig - Laptop users, quickly switch network and proxy configuration in different places
http://www.codeproject.com/csharp/oazswitchnetconfig.asp

Bob
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:jonastovsen
ID: 16964515
Thank you! The program on the link looks fine, but unfortunately I don't write C#. It would take me significant time to translate it.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 16964598
Good thing I can:

Imports Microsoft.Win32

''' <summary>
''' Summary description for IEProxy.
''' </summary>
Public Class IeProxy

#Region "Variables"
  Private Shared ReadOnly currentUser As RegistryKey = Registry.CurrentUser
  Private Shared _InternetSettings As RegistryKey
#End Region

#Region "Public static methods"
  ''' <summary>
  ''' Open the key where Internet Explorer store's its proxy setting
  ''' </summary>
  Private Shared Sub OpenInternetSettings()
    _InternetSettings = currentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
  End Sub


  ''' <summary>
  ''' Proxy Server name. It can be IP, IP:PORT or a HTTP URL with PORT
  ''' </summary>
  Public Shared Property ProxyServer() As String
    Get
      OpenInternetSettings()
      Dim value As String = DirectCast(_InternetSettings.GetValue("ProxyServer", String.Empty), String)
      _InternetSettings.Close()
      Return value
    End Get
    Set(ByVal Value As String)
      OpenInternetSettings()
      _InternetSettings.SetValue("ProxyServer", Value)
      _InternetSettings.Close()
    End Set
  End Property


  ''' <summary>
  ''' True means proxy setting is applied, otherwise proxy is ignored
  ''' </summary>
  Public Shared Property ProxyEnabled() As Boolean
    Get
      OpenInternetSettings()
      Dim value As Integer = DirectCast(_InternetSettings.GetValue("ProxyEnable", 0), Integer)
      _InternetSettings.Close()
      Return (value > 0)
    End Get
    Set(ByVal Value As Boolean)
      OpenInternetSettings()
      Dim setValue As Integer = (IIf(Value, 1, 0))
      _InternetSettings.SetValue("ProxyEnable", setValue)
      _InternetSettings.Close()
    End Set
  End Property

  Public Shared Property BypassProxyForLocal() As Boolean
    Get
      OpenInternetSettings()
      Dim value As String = DirectCast(_InternetSettings.GetValue("ProxyOverride", String.Empty), String)
      _InternetSettings.Close()
      ' If bypass proxy set, then it should contain <local>
      If value.IndexOf("<local>") >= 0 Then
        Return True
      Else
        Return False
      End If
    End Get
    Set(ByVal Value As Boolean)
      OpenInternetSettings()
      Dim existingValue As String = DirectCast(_InternetSettings.GetValue("ProxyOverride", String.Empty), String)
      If existingValue.IndexOf("<local>") >= 0 Then
        If Not Value Then
          existingValue = existingValue.Replace(";" + Environment.NewLine + "<local>", "")
        End If
      Else
        ' does not contain the local keyword. Add it.
        If Value Then
          existingValue += ";" + Environment.NewLine + "<local>"
        End If
      End If
      _InternetSettings.SetValue("ProxyOverride", existingValue)
      _InternetSettings.Close()
    End Set
  End Property
#End Region

End Class

Bob
0
 

Author Comment

by:jonastovsen
ID: 16968125
Fantastic!

Thank you for taking the time to translate the code!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 45
MailAddress in vb 4 36
VB.Net  Exporting Excel Woorkbook to PDF 7 60
vb.net dbnull syntax 1 13
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question