Online Verfügbarkeits Check?

  • VB.NET
  • .NET (FX) 3.0–3.5

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von Nikx.

    C#-Quellcode

    1. ​internal class ConnectionChecker
    2. {
    3. [DllImport("wininet.dll")]
    4. private static extern bool InternetGetConnectedState(out int connDescription, int ReservedValue);
    5. /// <summary>
    6. /// Checks if an internet connection is available.
    7. /// </summary>
    8. /// <returns>This function returns a boolean.</returns>
    9. public static bool IsConnectionAvailable()
    10. {
    11. int Desc;
    12. return InternetGetConnectedState(out Desc, 0);
    13. }
    14. }
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:
    Bitteschön

    Edit:

    VB.NET-Quellcode

    1. Friend Class ConnectionChecker
    2. <DllImport("wininet.dll")> _
    3. Private Shared Function InternetGetConnectedState(ByRef connDescription As Integer, ReservedValue As Integer) As Boolean
    4. End Function
    5. ''' <summary>
    6. ''' Checks if an internet connection is available.
    7. ''' </summary>
    8. ''' <returns>This function returns a boolean.</returns>
    9. Public Shared Function IsConnectionAvailable() As Boolean
    10. Dim Desc As Integer
    11. Return InternetGetConnectedState(Desc, 0)
    12. End Function
    13. End Class

    YoungPadawan schrieb:

    Das ist aber nur für C# ich bräuchte es für VB

    Na und? Dann konvertiere es Dir halt. Ich mache mir doch nicht extra die Arbeit für Dich, wenn ich es nur so habe. :P
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:
    Ich hoffe, folgendes geht:

    VB.NET-Quellcode

    1. If My.Computer.Network.IsAvailable Then
    2. MsgBox("Computer ist verbunden.")
    3. Else
    4. MsgBox("Computer ist nicht verbunden.")
    5. End If


    Beziehungsweise der Ping an die 8.8.8.8:

    VB.NET-Quellcode

    1. If My.Computer.Network.Ping("8.8.8.8") Then
    2. MsgBox("Server erfolgreich angepingt.")
    3. Else
    4. MsgBox("Zeitüberschreitung.")
    5. End If

    @FanMaderWeb Wird nicht klappen. Network.IsAvailable kann jedes Netzwerk sein, und der Ping wirft bei Zeitüberschreitung einen
    Error "Ausnahme wärend einer Pinganforderung", anstatt in den Else-Block zu springen. Hoffe ich bin hier noch auf dem neusten Stand.

    Grüße
    "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

    Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!