Solved

Programmatically change proxy settings

Posted on 2006-06-22
6
571 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now