tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
2
ZUGRIFFE
688
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Avatar von Vektor
    Vektor Vektor ist offline Mitglied Gold
    Registriert seit
    Oct 2003
    Beiträge
    156
    Hallo zusammen,

    ich habe wieder ein Problem . Und zwar möchte ich aus meinem Programm heraus ermitteln ob eine Verbindung mit dem Internet besteht, und falls nicht, den Standarddialog dazu aufrufen (Für die Standart-DFÜ-Verbindung). Diese soll dann eventuell auch wieder getrennt werden.

    Ich hab mir jetzt schon mal folgende API's rausgesucht und deklariert:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    
    Private Declare Function InternetDial Lib "wininet.dll" ( _
          ByVal hwndParent As Long, _
          ByVal lpszConiID As String, _
          ByVal dwFlags As Long, _
          ByRef hCon As Long, _
          ByVal dwReserved As Long) As Long
     
        Private Declare Function InternetHangUp Lib "wininet.dll" _
          (ByVal dwConnection As Long, ByVal dwReserved As Long) _
          As Long
     
        Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
        (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
     
        Private Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias _
        "RasEnumConnectionsA" ( _
        ByVal lprasconn As Object, ByVal lpcb As Long, ByVal lpcConnections As Long) As Long
     
        Private Structure RASCONN
            Dim dwSize As Integer
            Dim hRasConn As Integer
            <VBFixedArray(256)> Dim szEntryName() As Byte
            <VBFixedArray(16)> Dim szDeviceType() As Byte
            <VBFixedArray(128)> Dim szDeviceName() As Byte
     
            Public Sub Initialize()
                ReDim szEntryName(256)
                ReDim szDeviceType(16)
                ReDim szDeviceName(128)
            End Sub
        End Structure
    Das klappt aber nicht so wie ich will! (Oder ich kann einfach nicht damit umgehen ) Leider finde ich auch keine Anleitungen oder Hilfen zu den API's. Nun hoffe ich, wieder einmal, dass ihr mir helfen könnt und mir sagt wie ich sowas zum laufen bekomme.

    Vielen Dank...
     
    "Es gibt noch andere Welten als diese..."
    Stephen King || Der dunkle Turm

  2. #2
    Avatar von JensG
    JensG JensG ist offline Mitglied Platin
    Registriert seit
    Jun 2004
    Ort
    Gera (Thüringen)
    Beiträge
    517
    Hallo Vektor,

    schau dir mal das an.

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    
     
    Public Class Form1
        Inherits System.Windows.Forms.Form
     
        Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" _
            Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Integer, ByVal _
            lpszConnectionName As System.Text.StringBuilder, ByVal dwNameLen As Integer, _
            ByVal dwReserved As Integer) As Integer
     
        Public Declare Function InternetDial Lib "wininet.dll" (ByVal hwndParent As Integer, ByVal lpszConiID _
            As String, ByVal dwFlags As Integer, ByRef hCon _
            As Integer, ByVal dwReserved As Integer) As Integer
     
     
     
     
        Private Declare Function InternetAutodialHangup Lib "wininet.dll" _
        (ByVal dwReserved As Integer) As Integer
     
     
     
     
        Private Declare Function IsNetworkAlive Lib "Sensapi" (ByVal dwFlags As _
        Integer) As Integer
     
        Private Const NETWORK_ALIVE_LAN = &H1 'connection use net card
        Private Const NETWORK_ALIVE_WAN = &H2 'RAS connection
        Private Const NETWORK_ALIVE_AOL = &H4 'AOL connection (w9x only)
     
     
     
        Private Const INTERNET_CONNECTION_MODEM = &H1&
        Private Const INTERNET_CONNECTION_LAN = &H2&
        Private Const INTERNET_CONNECTION_PROXY = &H4&
        Private Const INTERNET_RAS_INSTALLED = &H10&
        Private Const INTERNET_CONNECTION_OFFLINE = &H20&
        Private Const INTERNET_CONNECTION_CONFIGURED = &H40&
     
        
     
        Const DIAL_UNATTENDED As Integer = &H8000&
        Const DIAL_FORCE_ONLINE As Integer = 1
        Const DIAL_FORCE_UNATTENDED As Integer = 2
     
     
     
        Public Structure RASENTRYNAME95
            Public dwSize As Integer
            Public szEntryName() As Byte
        End Structure
     
        Dim ConID As Integer, ConName As String
     
     
     
     
    #Region " Vom Windows Form Designer generierter Code "
     
        Public Sub New()
            MyBase.New()
     
            ' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
            InitializeComponent()
     
            ' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen
     
        End Sub
     
        ' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu bereinigen.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
     
        ' Für Windows Form-Designer erforderlich
        Private components As System.ComponentModel.IContainer
     
        'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer erforderlich
        'Sie kann mit dem Windows Form-Designer modifiziert werden.
        'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
        Friend WithEvents Button1 As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.Button1 = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(32, 40)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(152, 40)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Button1"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(440, 273)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
     
        End Sub
     
    #End Region
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
            Dim dwFlags As Integer
            Dim sNameBuf As System.Text.StringBuilder = New System.Text.StringBuilder(513)
            Dim sConnectionName As String
            Dim msg As String
            Dim lPos As Integer
            Dim iret As Integer
     
            iret = InternetGetConnectedStateEx(dwFlags, sNameBuf, sNameBuf.Capacity, 0&)
            If iret Then
                'Yes, you have active connection
                Dim CheckConnectionIGCS As Boolean
                CheckConnectionIGCS = True
                'Collect ExtraInfo:
                lPos = sNameBuf.Length
     
     
                If lPos > 0 Then sConnectionName = sNameBuf.ToString()
                Dim ConnectionInfo As Integer = dwFlags
     
                If (dwFlags And INTERNET_CONNECTION_LAN) Then
                    MsgBox("Your connection use LAN")
                ElseIf (dwFlags And INTERNET_CONNECTION_MODEM) Then
                    MsgBox("Your connection use Modem")
                End If
            Else
                If (dwFlags And INTERNET_CONNECTION_OFFLINE) Then
                    MsgBox("You use a LAN But You Are Not Connected")
                Else
                    MsgBox("Your use A Modem, But you are not connected")
     
                  
     
     
     
                    InternetDial(0, "DefaultDialUp", DIAL_FORCE_ONLINE, 0, 0)
     
     
     
     
                End If
            End If
     
     
     
     
        End Sub
    End Class
     

  3. #3
    Avatar von Vektor
    Vektor Vektor ist offline Mitglied Gold
    Registriert seit
    Oct 2003
    Beiträge
    156
    Hallo,

    vielen Dank für deine Antwort. Ich hab das jetzt mithilfe folgender API's gelöst.
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Int32, _
        ByVal dwReserved As Int32) As Boolean
     
        Private Declare Function InternetDial Lib "Wininet.dll" (ByVal hwndParent As IntPtr, _
        ByVal lpszConnectoid As String, ByVal dwFlags As Int32, ByRef lpdwConnection As Int32, _
        ByVal dwReserved As Int32) As Int32
     
        Private Declare Function InternetHangUp Lib "Wininet.dll" _
        (ByVal lpdwConnection As Int32, ByVal dwReserved As Int32) As Int32
     
        Private Declare Ansi Function RasEnumConnectionsA Lib _
          "RasApi32.DLL" (<[In](), Out()> ByVal lpRasConn As RASCONN(), ByRef lbcp As Integer, _
        ByRef lbcConnections As Integer) As Integer
    Aber dein Code gefällt mir auf den ersten Blick wesentlich besser, da man damit sogar ermitteln kann über welches Gerät man verbunden ist. Ich werde mal diese Lösung noch ausprobieren. Danke nochmal.
     
    "Es gibt noch andere Welten als diese..."
    Stephen King || Der dunkle Turm

Ähnliche Themen

  1. Antworten: 11
    Letzter Beitrag: 05.12.08, 14:31
  2. CMD Internetverbindung?
    Von DarkManX im Forum Microsoft Windows
    Antworten: 0
    Letzter Beitrag: 16.01.05, 00:24
  3. Internetverbindung tot
    Von Mogtroll im Forum Netzwerke
    Antworten: 0
    Letzter Beitrag: 08.03.04, 20:49
  4. Internetverbindung
    Von Deini im Forum Microsoft Windows
    Antworten: 2
    Letzter Beitrag: 01.12.03, 10:18
  5. Internetverbindung
    Von Nanaki im Forum Internet, DSL & Flatrate
    Antworten: 4
    Letzter Beitrag: 22.06.02, 22:42