Solved

Need network connection advice

Posted on 2004-10-05
7
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

626 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