Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking network drive "heartbeat"?

Status
Not open for further replies.

AncientTiger

Programmer
Jul 5, 2001
238
US
This may be a forehead slapper, but I've got to ask it anyway because I'm stumped...

I need a way to check if a network drive is still available that doens't hang my program up for over a minute if the network went down sometime after the program is ran.

Here's what's happening. I have a program that communicates with files/folders on a network drive. ON startup, the program checks to see if the network drive is visible. If it is, it continues on its merry way. However, if after the program is running, the network goes down, my program hangs for a little over a minute before it reports that the network drive is no longer available. As in (Not Responding) hangs :(

The routine I currently have in place to confirm the network drive availability looks something like this:
Code:
Set FSO = CreateObject("SCRIPTING.FILESYSTEMOBJECT")

'CHECK "HEARTBEAT"
DE = FSO.DRIVEEXISTS(MAIN.DRIVELETTER.Caption) 'The network drive letter
If DE = False Then CHECKNETDRIVE = False: Exit Function

As I said, if the network is up the the drive is visible when the program starts, no worries. But if it goes down, it's hanging me up pretty bad, and I'm at a loss on what to do.

Sorry if this is a noob question... self-taught programmers, OLD ones at that, sometimes need extra care and feeding


------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
Code:
Public Function IsReachable(strComputer As String) As Boolean ' strComputer can be name or IP address
    Dim objWMIService As Object
    Dim objPing As Object
    Dim objStatus As Variant
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" & strComputer & "' and StatusCode=0")
    
    For Each objStatus In objPing
        IsReachable = objStatus.StatusCode = 0
    Next
End Function

I feel like this might be what I'm looking for, but I'm not familiar with the WMI service... is there a way to modify this code to look by drive letter, rather than computer name?


------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
Well DRAT... figured out a workaround to checking by drive letter (just go the sharename of the drive and parsed out the source computer name), but STILL getting a very long timeout/program hang.

The WMI check DID work just as it should... just not the result I was looking for. Thanks for the effort HughLerwill :)

------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
> just not the result I was looking for

Well, it was written as a fast ping function, which means what is does quickly check if you have basic network connectivity to the computer in question. But no, it was never intended to verify if a specific folder was accessible.
 
And that was my intention... just to see if the drive was still connected/accessible. I know how to verify if files/folders exist or not ;)


------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
Sorry, should have been more explicit: it was never intended to verify if a specific folder or drive was accessible
 
IcmpSendEcho in Icmp.dll is more reliable in an application. It does not require that the heavyweight WMI Service be installed, running, and unsecured against standard user access.
 
IcmpSendEcho... Hmmm... would you mind giving some sample code on how I could check a connection with a network computer named "mynetworkservercomputer" on the network? Pretty please??

------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
let's be clear here, if IsReachable does not do what you need then neither will icmpsendecho since IsReachable works by sending the same ping (albeit via WMI rather than a direct API) as icmpsendecho

>would you mind giving some sample code

If you do decide to proceed, then a quick search in this very forum against icmpsendecho will provide several code examples.
 
Ok, I'll research it some.. thanks :)

------------------------------------
[yinyang] Over 20 years of programming, and still learning every day! [yinyang]
 
I agree that a ping only tells you that the server is running and reachable via a ping. It was really designed as a network connectivity test and nothing more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top