?
Solved

Programmatically change proxy settings

Posted on 2006-06-22
6
Medium Priority
?
589 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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