Advertisement
CorrM

Untitled

Jul 21st, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.68 KB | None | 0 0
  1. ' The structure we use for the information
  2.     ' to be interpreted correctly by API.
  3.     Public Structure Struct_INTERNET_PROXY_INFO
  4.         Public dwAccessType As Integer
  5.         Public proxy As IntPtr
  6.         Public proxyBypass As IntPtr
  7.     End Structure
  8.  
  9.     ' The Windows API function that allows us to manipulate
  10.     ' IE settings programmatically.
  11.     Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
  12.     (ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, _
  13.      ByVal lpdwBufferLength As Integer) As Boolean
  14.  
  15.     ' The function we will be using to set the proxy settings.
  16.     Private Sub RefreshIESettings(ByVal strProxy As String)
  17.         Const INTERNET_OPTION_PROXY As Integer = 38
  18.         Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
  19.         Dim struct_IPI As Struct_INTERNET_PROXY_INFO
  20.  
  21.         ' Filling in structure
  22.         struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
  23.         struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
  24.         struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")
  25.  
  26.         ' Allocating memory
  27.         Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
  28.  
  29.         ' Converting structure to IntPtr
  30.         System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
  31.         Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
  32.     End Sub
  33.  
  34. ' ======================
  35. ' Use
  36. RefreshIESettings("Adresse:potr")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement