Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - .NET

Страница: 1 |

 

  Вопрос: Set IE Proxy Добавлено: 04.12.08 17:13  

Автор вопроса:  Skywalker | Web-сайт: iSkywalker.ru | ICQ: 300-70-6пятьЪ 
подскажите как установить параметры прокси в IE на vpn соединение

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 Skywalker



ICQ: 300-70-6пятьЪ 

Вопросов: 62
Ответов: 545
 Web-сайт: iSkywalker.ru
 Профиль | | #1
Добавлено: 04.12.08 17:21
вот это устанавливает прокси для LAN, а мне нужно для инета, чот не нашол как

  1. Imports System
  2. Imports System.Runtime.InteropServices
  3. Imports System.ComponentModel
  4. Public Class Proxies
  5.     Public Shared Function SetProxy(ByVal strProxy As String) As Boolean
  6.         Return Proxies.SetProxy(strProxy, Nothing)
  7.     End Function
  8.     Public Shared Function SetProxy(ByVal strProxy As String, ByVal exceptions As String) As Boolean
  9.         Dim list As New InternetPerConnOptionList
  10.         Dim optionCount As Integer = IIf(String.IsNullOrEmpty(strProxy), 1, IIf(String.IsNullOrEmpty(exceptions), 2, 3))
  11.         Dim options As InternetConnectionOption() = New InternetConnectionOption(optionCount - 1) {}
  12.         options(0).m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS
  13.         options(0).m_Value.m_Int = IIf((optionCount < 2), 1, 3)
  14.         If (optionCount > 1) Then
  15.             options(1).m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER
  16.             options(1).m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy)
  17.             If (optionCount > 2) Then
  18.                 options(2).m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS
  19.                 options(2).m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(exceptions)
  20.             End If
  21.         End If
  22.         list.dwSize = Marshal.SizeOf(list)
  23.         list.szConnection = IntPtr.Zero
  24.         list.dwOptionCount = options.Length
  25.         list.dwOptionError = 0
  26.         Dim optSize As Integer = Marshal.SizeOf(GetType(InternetConnectionOption))
  27.         Dim optionsPtr As IntPtr = Marshal.AllocCoTaskMem((optSize * options.Length))
  28.         Dim i As Integer
  29.         For i = 0 To options.Length - 1
  30.             Dim opt As New IntPtr((optionsPtr.ToInt32 + (i * optSize)))
  31.             Marshal.StructureToPtr(options(i), opt, False)
  32.         Next i
  33.         list.options = optionsPtr
  34.         Dim ipcoListPtr As IntPtr = Marshal.AllocCoTaskMem(list.dwSize)
  35.         Marshal.StructureToPtr(list, ipcoListPtr, False)
  36.         Dim returnvalue As Integer = IIf(NativeMethods.InternetSetOption(IntPtr.Zero, InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, ipcoListPtr, list.dwSize), -1, 0)
  37.         If (returnvalue = 0) Then
  38.             returnvalue = Marshal.GetLastWin32Error
  39.         End If
  40.         Marshal.FreeCoTaskMem(optionsPtr)
  41.         Marshal.FreeCoTaskMem(ipcoListPtr)
  42.         If (returnvalue > 0) Then
  43.             Throw New Win32Exception(Marshal.GetLastWin32Error)
  44.         End If
  45.         Return (returnvalue < 0)
  46.     End Function
  47.     Public Shared Function UnsetProxy() As Boolean
  48.         Return Proxies.SetProxy(Nothing, Nothing)
  49.     End Function
  50. End Class
  51. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
  52. Public Structure InternetConnectionOption
  53.     Private Shared ReadOnly Size As Integer
  54.     Public m_Option As PerConnOption
  55.     Public m_Value As InternetConnectionOptionValue
  56.     Shared Sub New()
  57.         InternetConnectionOption.Size = Marshal.SizeOf(GetType(InternetConnectionOption))
  58.     End Sub
  59. End Structure
  60. Public Enum InternetOption As UInt32
  61.     ' Fields
  62.     INTERNET_OPTION_PER_CONNECTION_OPTION = &H4B
  63. End Enum
  64. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
  65. Public Structure InternetPerConnOptionList
  66.     Public dwSize As Integer
  67.     Public szConnection As IntPtr
  68.     Public dwOptionCount As Integer
  69.     Public dwOptionError As Integer
  70.     Public options As IntPtr
  71. End Structure
  72. Friend Class NativeMethods
  73.     ' Methods
  74.     <DllImport("WinInet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
  75.     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
  76.     End Function
  77.  
  78. End Class
  79. <Flags()> _
  80. Public Enum PerConnFlags
  81.     ' Fields
  82.     PROXY_TYPE_AUTO_DETECT = 8
  83.     PROXY_TYPE_AUTO_PROXY_URL = 4
  84.     PROXY_TYPE_DIRECT = 1
  85.     PROXY_TYPE_PROXY = 2
  86. End Enum
  87. Public Enum PerConnOption
  88.     ' Fields
  89.     INTERNET_PER_CONN_AUTOCONFIG_URL = 4
  90.     INTERNET_PER_CONN_FLAGS = 1
  91.     INTERNET_PER_CONN_PROXY_BYPASS = 3
  92.     INTERNET_PER_CONN_PROXY_SERVER = 2
  93. End Enum
  94. <StructLayout(LayoutKind.Explicit)> _
  95. Public Structure InternetConnectionOptionValue
  96.     ' Fields
  97.     <FieldOffset(0)> _
  98.     Public m_FileTime As FILETIME
  99.     <FieldOffset(0)> _
  100.     Public m_Int As Integer
  101.     <FieldOffset(0)> _
  102.     Public m_StringPtr As IntPtr
  103. End Structure

Ответить

Номер ответа: 2
Автор ответа:
 Skywalker



ICQ: 300-70-6пятьЪ 

Вопросов: 62
Ответов: 545
 Web-сайт: iSkywalker.ru
 Профиль | | #2
Добавлено: 04.12.08 20:07
Все уже нинада, нада в list.szConnection передавать имя соединения

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам