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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I check if a computer is connected without delay 1

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I am trying to check report files in a number of remote computers but if a computer is not switched on it takes forever.

My computer seems to freeze for a minute every time it cant connect for any reason.

I have tried opening the same file in every computer in turn (from a list) Eg - - - -

On error goto ComputerNotOn
For Item = 1 to 20
Open "\\" & IPAddress(Item) & "\c\ReportFile.txt" for Input as #1
Close #1
Next

Same using FileSystemObjects Getfile

But they all wait for a long long time when not connected.

Is there an instant way of seeing if a computer with a known IP address is there or not?
 
One though I had is if I could do the same as ping from the command line and store the answer?
That would be a bit quicker but I would like it to be instant like using Wininet on the internet but how do you use that on just a LAN?
 
More WMI for you Ted ...
Code:
[blue]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[/blue]
 
You are a genius
It only takes a second if the computer is not there
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top