Solved

Programmatically change proxy settings

Posted on 2006-06-22
6
583 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Industry Leaders: 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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