Solved

Need network connection advice

Posted on 2004-10-05
7
168 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:malanois
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12232641
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.
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12241722
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
0
 

Author Comment

by:malanois
ID: 12243770
JAMES

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


Thanks

malanois
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:malanois
ID: 12249155
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



0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12255908
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
0
 

Author Comment

by:malanois
ID: 12259759
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



0
 
LVL 5

Accepted Solution

by:
naiea1231 earned 500 total points
ID: 12265766
Ahh, don't worry about the wscript.echo, its just a way to use vbscript to report back

You can just change that to

MsgBox(sClient & " is responding")
and
MsgBox(sClient & " is not responding")

However, those lines are only used to report back whether the ping was successful or not. If you want to make use of the input its probably best to replace that with variables such as, when it responds:
PingSuccess = 1

And when it fails
PingSuccess = 0

You can then use this result later on, or return the value when you call the function etc.

If you have any further questions, don't hesitate to ask

James

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question