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.GetLogicalDri ves()
Console.WriteLine(DriveLet ter)
AllDrives.Add(DriveLetter. Substring( 0, 1))
Next
On Error Resume Next
If Not AllDrives.Contains("Z") Then
Dim net
net = CreateObject("WScript.Netw ork")
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
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.GetLogicalDri
Console.WriteLine(DriveLet
AllDrives.Add(DriveLetter.
Next
On Error Resume Next
If Not AllDrives.Contains("Z") Then
Dim net
net = CreateObject("WScript.Netw
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
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:{imper sonationLe vel=impers onate}//" & _
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
'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:{imper
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
ASKER
JAMES
That is what I am looking for, I will give it a try and lwt you know.'
Thanks
malanois
That is what I am looking for, I will give it a try and lwt you know.'
Thanks
malanois
ASKER
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
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
James
ASKER
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:{imper sonationLe vel=impers onate}//" & _
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
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:{imper
shost & "/root/cimv2").ExecQuery("
"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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_i
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.