Hack Forums
[.NET] [Source] Proxy Changer [Source] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Source] Proxy Changer [Source] (/showthread.php?tid=1614687)



[Source] Proxy Changer [Source] - khvex - Aug 17, 2011

We'll I've created a 'proxy changer' that enables and disables the proxy in your settings, this saves time as you don't have to navigate through 10 windows to get to it.

Now the code is below but there is one KEY problem. For the proxy change to take effect you still have to navigate to it.

Please help!

Code
Imports Microsoft.Win32

Public Class Form1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim proxy As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
        proxy.SetValue("ProxyEnable", 0)
        'Created By Coyney!
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim proxy As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True)
        proxy.SetValue("ProxyEnable", 1)
        'Created By Coyney!
    End Sub



* - SIM-964740 - Mar 2, 2012

Testing it as we speak, hope it works XD!


* - Eternal Darkness - Mar 2, 2012

Here's a easy way:
Code
Imports System.Runtime.InteropServices
Public Class Form1
#Region "Using Proxy"
    <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
    Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
    End Function

    Public Structure Struct_INTERNET_PROXY_INFO
  Public dwAccessType As Integer
  Public proxy As IntPtr
  Public proxyBypass As IntPtr
    End Structure

    Private Sub UseProxy(ByVal strProxy As String)
  Const INTERNET_OPTION_PROXY As Integer = 38
  Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

  Dim struct_IPI As Struct_INTERNET_PROXY_INFO

  struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
  struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
  struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

  Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

  Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

  Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
    End Sub
#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  UseProxy("PROXY:PORT")
  WebBrowser1.Navigate("http://www.whatismyip.com/") ' Or other site you want to load.
    End Sub

End Class

Source: https://hackforums.net/forum/Thread-VB-NET-UPDATED-Use-Proxy-On-WebBrowser-Source , which is from http://www.youtube.com/watch?v=Bi0NyqjRh0Y


* - Kazooo - Mar 27, 2012

Thank you Eternal for linking this. 


* - #Blow - Nov 3, 2013

Thanks so much Eternal for this source!