Link to home
Start Free TrialLog in
Avatar of malanois
malanois

asked on

Need network connection advice

I created a class:


Public Class NetworkStatus
    Dim online

    Public Property Netstatus()
        Get
            Call Online_Offline()
            Return online
        End Get
        Set(ByVal Value)
            online = Value
        End Set
    End Property

    Public Sub Online_Offline()
        '  Dim online
        Dim DriveLetter As String
        Dim AllDrives As New ArrayList
        For Each DriveLetter In IO.Directory.GetLogicalDrives()
            Console.WriteLine(DriveLetter)
            AllDrives.Add(DriveLetter.Substring(0, 1))
        Next
        On Error Resume Next

        If Not AllDrives.Contains("Z") Then
            Dim net
            net = CreateObject("WScript.Network")
            net.MapNetworkDrive("Z:", "\\winn\gssectssec")

        End If
        If AllDrives.Contains("Z") Then
            online = True
        Else
            online = False
        End If

    End Sub
End Class


However, I call on this class everytime to determine which database im going to connect.  I am finding out that if i connected, then went offline, MY Z: is still active.


My question is:

Is there a way to check the network status and get a return value back, such as

If ping http:www.yahoo.com successful Then
bla bla
else
bla bla

Or any other suggestions
Avatar of eozz_2000
eozz_2000

Jejeje... I have a not very useful way... I do a FTP to the server with this command:

Shell("FTP -s:Command.dat", AppWindowStyle.Hide, True, 5000)

in Command.dat I have the commands needed to get the file:

open
my_server
my_user
my_password
get
remote_file
local_file_path_to_store_it
bye

and then, I check if the file exists after the ftp has finished his execution.  Obviously the file is 1 byte long., and I try to delete it when the program starts.
I use this in one of my scripts:

'leave this as it is, represents where the ping originates
sHost            = "."

'change this to the ip or url of where you want to ping
sClient = "yahoo.com"

Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
            sHost & "/root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus " & _
            "WHERE Address = '" + sClient + "'")

'process ping results
For Each oPingResult In cPingResults
      If oPingResult.StatusCode = 0 Then
            WScript.Echo sClient & " is responding"
                  Else
            WScript.Echo sClient & " is not responding"
      End If
Next



Give that a try, seems to be what your looking for.
James
Avatar of malanois

ASKER

JAMES

That is what I am looking for, I will give it a try and lwt you know.'


Thanks

malanois
James,

I must not be declaring something correctly.

It will not allow the set command  ..      Set cPingResul   ----- It keeps taking Set away


 Dim shost, sClient
        Dim cPingResults
        Dim oPingResult As Object

what am I missing here



Ahh, since your using vb.net there is not need to use set, as the above script was originally written in vbscript. Just allow it to remove the set, and it should be fine. Let me know it goes.

James
man o man am i having issues:

  Dim shost, sClient
        Dim cPingResults
        Dim oPingResult As Object

        Dim WScript

        shost = "."

        'change this to the ip or url of where you want to ping
        sClient = "yahoo.com"

       cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                      shost & "/root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus " & _
                 "WHERE Address = '" + sClient + "'")

        'process ping results
        For Each oPingResult In cPingResults
            If oPingResult.StatusCode = 0 Then
                WScript.Echo(sClient & " is responding")  <<<<<<<<<<<<<
            Else
                WScript.Echo(sClient & " is not responding")<<<<<<<<<<<<  WScript has no object set error
            End If
        Next

I have tried creating variables,
setiing things to objects like above:  It still will not run?????????


This is what Im looking for just need to get it to work



ASKER CERTIFIED SOLUTION
Avatar of naiea1231
naiea1231

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial