Use Proxy


SUBMITTED BY: Guest

DATE: Dec. 7, 2013, 8:17 a.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 1072

  1. #region "Using Proxy"
  2. <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
  3. Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
  4. End Function
  5. Public Structure Struct_INTERNET_PROXY_INFO
  6. Public dwAccessType As Integer
  7. Public proxy As IntPtr
  8. Public proxyBypass As IntPtr
  9. End Structure
  10. Private Sub UseProxy(ByVal strProxy As String)
  11. Const INTERNET_OPTION_PROXY As Integer = 38
  12. Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
  13. Dim struct_IPI As Struct_INTERNET_PROXY_INFO
  14. struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
  15. struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
  16. struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
  17. Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
  18. Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
  19. Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
  20. End Sub
  21. #end region
  22. -------------------------------
  23. UseProxy("Proxy")

comments powered by Disqus