вот это устанавливает прокси для LAN, а мне нужно для инета, чот не нашол как
- Imports System
- Imports System.Runtime.InteropServices
- Imports System.ComponentModel
- Public Class Proxies
- Public Shared Function SetProxy(ByVal strProxy As String) As Boolean
- Return Proxies.SetProxy(strProxy, Nothing)
- End Function
- Public Shared Function SetProxy(ByVal strProxy As String, ByVal exceptions As String) As Boolean
- Dim list As New InternetPerConnOptionList
- Dim optionCount As Integer = IIf(String.IsNullOrEmpty(strProxy), 1, IIf(String.IsNullOrEmpty(exceptions), 2, 3))
- Dim options As InternetConnectionOption() = New InternetConnectionOption(optionCount - 1) {}
- options(0).m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS
- options(0).m_Value.m_Int = IIf((optionCount < 2), 1, 3)
- If (optionCount > 1) Then
- options(1).m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER
- options(1).m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy)
- If (optionCount > 2) Then
- options(2).m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS
- options(2).m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(exceptions)
- End If
- End If
- list.dwSize = Marshal.SizeOf(list)
- list.szConnection = IntPtr.Zero
- list.dwOptionCount = options.Length
- list.dwOptionError = 0
- Dim optSize As Integer = Marshal.SizeOf(GetType(InternetConnectionOption))
- Dim optionsPtr As IntPtr = Marshal.AllocCoTaskMem((optSize * options.Length))
- Dim i As Integer
- For i = 0 To options.Length - 1
- Dim opt As New IntPtr((optionsPtr.ToInt32 + (i * optSize)))
- Marshal.StructureToPtr(options(i), opt, False)
- Next i
- list.options = optionsPtr
- Dim ipcoListPtr As IntPtr = Marshal.AllocCoTaskMem(list.dwSize)
- Marshal.StructureToPtr(list, ipcoListPtr, False)
- Dim returnvalue As Integer = IIf(NativeMethods.InternetSetOption(IntPtr.Zero, InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, ipcoListPtr, list.dwSize), -1, 0)
- If (returnvalue = 0) Then
- returnvalue = Marshal.GetLastWin32Error
- End If
- Marshal.FreeCoTaskMem(optionsPtr)
- Marshal.FreeCoTaskMem(ipcoListPtr)
- If (returnvalue > 0) Then
- Throw New Win32Exception(Marshal.GetLastWin32Error)
- End If
- Return (returnvalue < 0)
- End Function
- Public Shared Function UnsetProxy() As Boolean
- Return Proxies.SetProxy(Nothing, Nothing)
- End Function
- End Class
- <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
- Public Structure InternetConnectionOption
- Private Shared ReadOnly Size As Integer
- Public m_Option As PerConnOption
- Public m_Value As InternetConnectionOptionValue
- Shared Sub New()
- InternetConnectionOption.Size = Marshal.SizeOf(GetType(InternetConnectionOption))
- End Sub
- End Structure
- Public Enum InternetOption As UInt32
-
- INTERNET_OPTION_PER_CONNECTION_OPTION = &H4B
- End Enum
- <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
- Public Structure InternetPerConnOptionList
- Public dwSize As Integer
- Public szConnection As IntPtr
- Public dwOptionCount As Integer
- Public dwOptionError As Integer
- Public options As IntPtr
- End Structure
- Friend Class NativeMethods
-
- <DllImport("WinInet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
- Public Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As InternetOption, ByVal lpBuffer As IntPtr, ByVal dwBufferLength As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
-
- End Class
- <Flags()> _
- Public Enum PerConnFlags
-
- PROXY_TYPE_AUTO_DETECT = 8
- PROXY_TYPE_AUTO_PROXY_URL = 4
- PROXY_TYPE_DIRECT = 1
- PROXY_TYPE_PROXY = 2
- End Enum
- Public Enum PerConnOption
-
- INTERNET_PER_CONN_AUTOCONFIG_URL = 4
- INTERNET_PER_CONN_FLAGS = 1
- INTERNET_PER_CONN_PROXY_BYPASS = 3
- INTERNET_PER_CONN_PROXY_SERVER = 2
- End Enum
- <StructLayout(LayoutKind.Explicit)> _
- Public Structure InternetConnectionOptionValue
-
- <FieldOffset(0)> _
- Public m_FileTime As FILETIME
- <FieldOffset(0)> _
- Public m_Int As Integer
- <FieldOffset(0)> _
- Public m_StringPtr As IntPtr
- End Structure
Ответить
|