Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

Hanz
Lv 6

VB.net - Umschalten zwischen Online- und Offlinebetrieb?

Hallo,

ich hab da ein Programm das auf das Internet zugreift. Seit ich Windows 7 verwende, kann es immer wieder plötzlich keine Verbindung herstellen, obwohl das Internet online ist und Firefox funktioniert.

Erst als mich neulich die Virensoftware zum Update fragte, ob ich in den Online-Modus wechseln wolle, wurde mir klar dass es daran liegt, weil das Programm hinterher wieder funktionierte.

Jetzt möchte ich in VB.net ein kleines Tool schreiben, das mir den Modus des Systems anzeigt und einen manuellen Wechsel erlaubt.

Leider finde ich per Google nichts für .net, nur für VB6

http://www.vbarchiv.net/tipps/tipp_491-umschalten-...

Wie kann ich das in .net realisieren?

Update:

Das Programm erzeugt nur fehler beim Abruf, VarPtr hat keinen Wert.

Beim Online Check kommt:

PInvokeStackImbalance wurde erkannt.

Message: Ein Aufruf an die PInvoke-Funktion "WindowsApplication1!WindowsApplication1.Form1::InternetQueryOption" hat das Gleichgewicht des Stapels gestört. Wahrscheinlich stimmt die verwaltete PInvoke-Signatur nicht mit der nicht verwalteten Zielsignatur überein. Überprüfen Sie, ob die Aufrufkonvention und die Parameter der PInvoke-Signatur mit der nicht verwalteten Zielsignatur übereinstimmen.

'###

Imports System.Runtime.InteropServices

Public Class Form1

'###

' zunächst die benötigten Deklarationen

Private Declare Function InternetQueryOption Lib "wininet" _

Alias "InternetQueryOptionA" ( _

ByVal hInternet As Long, _

ByVal dwOption As Long, _

ByRef lpBuffer As Long, _

ByRef dwBufferLength As Long) As Long

'Private Const INTERNET_OPTION_CONNECTED_STATE = 50

'Private Const INTERNET_STATE_DISCONNECTED_B

Update 2:

' Globaler Offline-Modus gestartet?

Private Function SystemOffline() As Boolean

Dim lState As Long

If InternetQueryOption(0, _

INTERNET_OPTION_CONNECTED_STATE, _

lState, Len(lState)) <> 0 Then

SystemOffline = (lState And _

INTERNET_STATE_DISCONNECTED_BY_USER)

End If

End Function

'###

Public Structure Struct_INTERNET_PROXY_INFO

Public dwAccessType As Integer

Public proxy As IntPtr

Public proxyBypass As IntPtr

End Structure

<DllImport("wininet.dll", SetLastError:=True)> _

Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean

End Function

' zunächst die benötigten Deklarationen

Private Declare Function InternetSetOption Lib "wininet" _

Alias "InternetSetOptionA" ( _

ByVal hInternet As Long, _

ByVal dwOption As Long, _

Update 3:

ByVal lpBuffer As Long, _

ByVal dwBufferLength As Long) As Long

Private Structure INTERNET_CONNECTED_INFO

Dim dwConnectedState As Long

Dim dwFlags As Long

End Structure

Private Const INTERNET_OPTION_CONNECTED_STATE = 50

Private Const INTERNET_STATE_CONNECTED = &H1

Private Const INTERNET_STATE_DISCONNECTED_BY_USER = &H10

Private Const ISO_FORCE_DISCONNECTED = &H1

' System in den Offlinebetrieb setzen

Public Sub System_SetOffline()

Dim uINFO As INTERNET_CONNECTED_INFO

Dim lResult As Long

Dim VarPtr

With uINFO

.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER

.dwFlags = ISO_FORCE_DISCONNECTED

End With

lResult = InternetSetOption(0, _

INTERNET_OPTION_CONNECTED_STATE, _

VarPtr(uINFO), Len(uINFO))

End Sub

' System in Onlinemodus setzen

Public Sub System_SetOnline()

Dim uINFO As INTERNET_CONNECTED_INFO

Dim

Update 4:

Dim VarPtr

With uINFO

.dwConnectedState = INTERNET_STATE_CONNECTED

End With

lResult = InternetSetOption(0, _

INTERNET_OPTION_CONNECTED_STATE, _

VarPtr(uINFO), Len(uINFO))

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MsgBox(SystemOffline())

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Call System_SetOnline()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Call System_SetOffline()

End Sub

End Class

1 Antwort

Bewertung
  • Anonym
    vor 1 Jahrzehnt
    Beste Antwort

    Du musst folgendes deklarieren:

    Public Structure Struct_INTERNET_PROXY_INFO

    Public dwAccessType As Integer

    Public proxy As IntPtr

    Public proxyBypass As IntPtr

    End Structure

    <DllImport("wininet.dll", SetLastError := True)> _

    Private Shared Function InternetSetOption(hInternet As IntPtr, dwOption As Integer, lpBuffer As IntPtr, lpdwBufferLength As Integer) As Boolean

    End Function

    Dann kannst du die Funktion InternetSetOption() aufrufen, mit den Parametern aus deinem VB6-Code, du musst nur mit den IntPtr etwas aufpassen.

    Grüße, JasonDelife.

Haben Sie noch Fragen? Jetzt beantworten lassen.