| |
| In diesem Forum haben Sie die Möglichkeit Kommentare, Fragen und Verbesserungsvorschläge zu den im vb@rchiv gelisteten Tipps und Workshops zu posten.
Hinweis: Ein neues Thema kann immer nur über die jeweilige Tipps & Tricks bzw. Workshop Seite eröffnet werden! | Fragen zu Tipps & Tricks und Workshops im vb@rchivRe: IE Proxy ändern mit VB.NET | | | Autor: BigPig | Datum: 22.03.10 14:45 |
| Oh je, gibt es da auch eine Übersetzung für VB.NET?
Das Leben ist wie eine H?hnerleiter
Kurz und beschissen | |
Re: IE Proxy ändern mit VB.NET | | | Autor: BigPig | Datum: 22.03.10 15:14 |
| Also ich habe versucht den C#-Quelltext nach VB zu übersetzen.
Jetzt habe ich hierbei folgendes Problem:
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Class frmProxy
<DllImport("wininet.dll")> Private Shared Function InternetSetOption( _
ByVal hInternet As IntPtr, _
ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal _
dwBufferLength As Integer) As Boolean
Dim INTERNET_OPTION_SETTINGS_CHANGED As Integer = 39
Dim INTERNET_OPTION_REFRESH As Integer = 37
Dim settingsReturn, refreshReturn As Boolean InternetSetOption wird blau(wellig) unterstrichen mit dem Hinweis:
System.Runtime.InteropServices.DllImportAttribute kann nicht auf "Sub","Function" oder "Operator" angewendet werden, die text enthalten
Was habe ich falsch gemacht?
Das Leben ist wie eine H?hnerleiter
Kurz und beschissen
Beitrag wurde zuletzt am 22.03.10 um 15:20:27 editiert. | |
Re: IE Proxy ändern mit VB.NET | | | Autor: Halvar66 | Datum: 23.03.10 11:27 |
| Danke, das mit dem DllImport geht jetzt.
Ich habe inzwischen aber festgestellt, das der Tipp nur bis IE6 funktioniert. Ab IE7 geht der Weg etwas anders.
Ein Beispiel für VB5+6 findet man hier: http://www.vbforums.com/showthread.php?t=449751
Ich habe mich dann darangesetzt das ganze für VB.NET zu transferieren. Allerdings scheitere ich.
Das Problem scheint bei dem dritten zu übergebenden Parameter zu liegen. Ich hoffe es findet sich
eine Lösung dafür. Leider bin ich noch nicht so fit in VB.NET und wäre für jede Hilfe dankbar.
Hier mein Quellcode (Teil 1):
#Region "Internet Connection Change"
Private Structure INTERNET_PER_CONN_OPTION
Public dwOption As Long
Public dwValue1 As Long
Public dwValue2 As Long
End Structure
Private Structure INTERNET_PER_CONN_OPTION_LIST
Public dwSize As Long
Public pszConnection As Long
Public dwOptionCount As Long
Public dwOptionError As Long
Public pOptions As Long
End Structure
Private Const INTERNET_PER_CONN_FLAGS As Long = 1
Private Const INTERNET_PER_CONN_PROXY_SERVER As Long = 2
Private Const INTERNET_PER_CONN_PROXY_BYPASS As Long = 3
Private Const PROXY_TYPE_DIRECT As Long = &H1
Private Const PROXY_TYPE_PROXY As Long = &H2
Private Const INTERNET_OPTION_REFRESH As Long = 37
Private Const INTERNET_OPTION_SETTINGS_CHANGED As Long = 39
Private Const INTERNET_OPTION_PER_CONNECTION_OPTION As Long = 75
<DllImport("wininet.dll")> Shared Function InternetSetOption(ByVal _
hInternet As IntPtr, _
ByRef dwOption _
As Integer, _
ByRef lpBuffer _
As IntPtr, _
ByVal _
dwBufferLength _
As Integer) As _
Boolean
End Function
Private Function VarPtr(ByVal e As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
Dim GC2 As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return GC2
End Function
Private Function StringToByteArray(ByRef str As String) As Byte()
'Return Convert.FromBase64String(str)
Return System.Text.Encoding.Default.GetBytes(str)
End Function | |
Re: IE Proxy ändern mit VB.NET | | | Autor: Halvar66 | Datum: 23.03.10 11:28 |
| Hier Quellcode (Teil 2):
' Set Proxy
Public Function SetConnectionOptions(ByVal conn_name As String, ByVal _
proxy_full_addr As String) As Boolean
' conn_name: active connection name. (LAN = "")
' proxy_full_addr : eg "193.28.73.241:8080"
Dim list As INTERNET_PER_CONN_OPTION_LIST
Dim bReturn As Boolean
Dim dwBufSize As Long
Dim options(0 To 2) As INTERNET_PER_CONN_OPTION
Dim abConnName() As Byte
Dim abProxyServer() As Byte
Dim abProxyBypass() As Byte
Dim proxy_bypass As String
dwBufSize = Len(list)
' Fill out list struct.
'allocate memory
list.dwSize = Len(list)
' NULL == LAN, otherwise connection name.
conn_name &= vbNullChar
abConnName = StringToByteArray(conn_name)
list.pszConnection = VarPtr(abConnName(0))
' Set three options.
list.dwOptionCount = 3
' Set flags.
options(0).dwOption = INTERNET_PER_CONN_FLAGS
options(0).dwValue1 = PROXY_TYPE_DIRECT Or PROXY_TYPE_PROXY
' Set proxy name.
options(1).dwOption = INTERNET_PER_CONN_PROXY_SERVER
proxy_full_addr &= vbNullChar
abProxyServer = StringToByteArray(proxy_full_addr)
options(1).dwValue1 = VarPtr(abProxyServer(0)) '//"http://proxy:80"
' Set proxy override.
options(2).dwOption = INTERNET_PER_CONN_PROXY_BYPASS
proxy_bypass = "local" & vbNullChar
abProxyBypass = StringToByteArray(proxy_bypass)
options(2).dwValue1 = VarPtr(abProxyBypass(0))
list.pOptions = VarPtr(options(0))
' Make sure the memory was allocated.
If (0& = list.pOptions) Then
' Return FALSE if the memory wasn't allocated.
Debug.Print("Failed to allocate memory in SetConnectionOptions()")
SetConnectionOptions = 0
End If
' Set the options on the connection.
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf( _
list))
bReturn = InternetSetOption(IntPtr.Zero, _
INTERNET_OPTION_PER_CONNECTION_OPTION, intptrStruct, dwBufSize)
' Free the allocated memory.
Erase options
Erase abConnName
Erase abProxyServer
Erase abProxyBypass
dwBufSize = 0
list.dwOptionCount = 0
list.dwSize = 0
list.pOptions = 0
list.pszConnection = 0
Call InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, _
IntPtr.Zero, 0)
Call InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, _
IntPtr.Zero, 0)
SetConnectionOptions = bReturn
End Function
' Disable Proxy
Public Function DisableConnectionProxy(ByVal conn_name As String) As Boolean
' conn_name: active connection name. (LAN = "")
Dim list As INTERNET_PER_CONN_OPTION_LIST
Dim bReturn As Boolean
Dim dwBufSize As Long
Dim options(0) As INTERNET_PER_CONN_OPTION
Dim abConnName() As Byte
dwBufSize = Len(list)
' Fill out list struct.
list.dwSize = Len(list)
' NULL == LAN, otherwise connectoid name.
conn_name &= vbNullChar
abConnName = StringToByteArray(conn_name)
list.pszConnection = VarPtr(abConnName(0))
' Set three options.
list.dwOptionCount = 1
' Set flags.
options(0).dwOption = INTERNET_PER_CONN_FLAGS
options(0).dwValue1 = PROXY_TYPE_DIRECT
list.pOptions = VarPtr(options(0))
' Make sure the memory was allocated.
If (0 = list.pOptions) Then
' Return FALSE if the memory wasn't allocated.
Debug.Print("Failed to allocate memory in DisableConnectionProxy()")
DisableConnectionProxy = 0
End If
' Set the options on the connection.
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf( _
list))
bReturn = InternetSetOption(IntPtr.Zero, _
INTERNET_OPTION_PER_CONNECTION_OPTION, intptrStruct, dwBufSize)
' Free the allocated memory.
Erase options
Erase abConnName
dwBufSize = 0
list.dwOptionCount = 0
list.dwSize = 0
list.pOptions = 0
list.pszConnection = 0
Call InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, _
IntPtr.Zero, 0)
Call InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, _
IntPtr.Zero, 0)
DisableConnectionProxy = bReturn
End Function
#End Region | |
Re: IE Proxy ändern mit VB.NET | | | Autor: Halvar66 | Datum: 23.03.10 12:29 |
| 1. Sorry wegen des Benutzerkontos
2. Bzgl. Beispiel HABE ich einen Link gepostet
3. Der Quellcode ist KEIN Beispiel, sondern das Ergebnis der versuchten Übersetzung meinerseits nach VB.NET | |
Re: IE Proxy ändern mit VB.NET | | | Autor: Halvar66 | Datum: 23.03.10 13:02 |
| Ziemlich den gleichen? Wenn es sich auf VB.NET bezieht, gib doch mal bitte den Link.
So wie es aussieht habe ich es nicht gefunden. Vielleicht hilft es mir ja weiter. Ich habe noch eine kürzere
Alternative gefunden - hier -> http://www.stalkpire.de/blog/280.aspx - Aber da habe ich
dasselbe Problem, das es nur nach einem Neustart des Programms wirksam wird. | |
Re: IE Proxy ändern mit VB.NET (Gelöst) | | | Autor: Halvar66 | Datum: 23.03.10 14:07 |
| Dein Link war ein Volltreffer! JETZT funktioniert es.
Du hattest recht damit, das mein Code und der aus Link fast identisch sind, aber eben nur fast.
Ich mußte wohl irgendwo noch einen kleinen Fehler drin gehabt haben.
Wäre schon, wenn du in dem Tipp den Hinweis gibst, das dein Code nur bis IE6 geht und der aus
dem Link ab IE 7 zu verwenden ist, wobei es auch für die niedrigeren IE-Versionen gehen soll.
Beitrag wurde zuletzt am 23.03.10 um 14:09:46 editiert. | |
Re: IE Proxy ändern mit VB.NET | | | Autor: Damian | Datum: 06.05.10 10:31 |
| Hallo zusammen,
die Lösung unter dem Link ist wirklich SUPER. Aber weiß von euch zufällig jemand, wie ich auch den Flag "Proxyserver für lokale Adressen umgehen" setzen kann?
Habe gesucht und gesucht, aber leider nichts passendes gefunden.
Für einen hilfreichen Tipp wäre ich Dankbar....
Grüße
Daniel | |
| Sie sind nicht angemeldet! Um einen neuen Beitrag schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
sevISDN 1.0
Überwachung aller eingehender Anrufe!
Die DLL erkennt alle über die CAPI-Schnittstelle eingehenden Anrufe und teilt Ihnen sogar mit, aus welchem Ortsbereich der Anruf stammt. Weitere Highlights: Online-Rufident, Erkennung der Anrufbehandlung u.v.m. Weitere InfosTipp des Monats sevGraph (VB/VBA)
Grafische Auswertungen
Präsentieren Sie Ihre Daten mit wenig Aufwand in grafischer Form. sevGraph unterstützt hierbei Balken-, Linien- und Stapel-Diagramme (Stacked Bars), sowie 2D- und 3D-Tortendiagramme und arbeitet vollständig datenbankunabhängig! Weitere Infos
|