Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need network connection advice

Posted on 2004-10-05
7
Medium Priority
?
172 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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