Solved

Programmatically change proxy settings

Posted on 2006-06-22
6
574 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
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 …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

12 Experts available now in Live!

Get 1:1 Help Now