Find Computer over network

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NSF12345
    New Member
    • Aug 2006
    • 21

    #1

    Find Computer over network

    Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\o ldpc\main share\Folder\fi le.txt") Then" way of finding if the file exists, but i want to make it so that it tries to look for the computer, not the file. At the moment this is how i am finding and copying the file:

    If FileExists("\\o ldpc\main share\Folder\fi le.txt") Then
    FileCopy "\\oldpc\ma in share\Folder\fi le.txt", "C:\Documen ts and Settings\All Users\Desktop\b ack ups\file.txt"
    else
    msgbox "Error"
    end if

    Public Function FileExists(Fnam e As String) As Boolean

    If Fname = "" Or Right(Fname, 1) = "\" Then
    FileExists = False: Exit Function
    End If

    FileExists = (Dir(Fname) <> "")

    End Function

    Instead of finding the file, i want it to find the PC, because, although the PC is connected, the file might not be at the location specified so it errors, and i want TWO different error messages. 1 saying the file is not at location, and 1 saying the computer is unable to be located. Can anyone help?
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi there,

    There are few ways to find a computer over the network, Windows Management Instrumentation (WMI) is very useful, instead lets focus on a simpler method, ping command is will solve your prob i guess, kindly refer to below code segment,

    Code:
    Private Type QOCINFO
      dwSize As Long
      dwFlags As Long
      dwInSpeed As Long 'in bytes/second
      dwOutSpeed As Long 'in bytes/second
    End Type
    
    Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
    
    Private Sub Form_Load()
      Dim Ret As QOCINFO
      Dim IP As String
      Ret.dwSize = Len(Ret)
      'Put desired IP here
      IP = "127.0.0.1"
    
      If IsDestinationReachable(IP, Ret) = 0 Then
        MsgBox "The destination cannot be reached!"
      Else
        MsgBox "The destination can be reached!" + vbCrLf + _
        "The speed of data coming in from the destination is " +  Format$(Ret.dwInSpeed / 1048576, "#.0") + " Mb/s," + vbCrLf + _
        "and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1048576, "#.0") + " Mb/s."
      End If
    End Sub
    Originally posted by NSF12345
    Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\o ldpc\main share\Folder\fi le.txt") Then" way of finding if the file exists, but i want to make it so that it tries to look for the computer, not the file. At the moment this is how i am finding and copying the file:

    If FileExists("\\o ldpc\main share\Folder\fi le.txt") Then
    FileCopy "\\oldpc\ma in share\Folder\fi le.txt", "C:\Documen ts and Settings\All Users\Desktop\b ack ups\file.txt"
    else
    msgbox "Error"
    end if

    Public Function FileExists(Fnam e As String) As Boolean

    If Fname = "" Or Right(Fname, 1) = "\" Then
    FileExists = False: Exit Function
    End If

    FileExists = (Dir(Fname) <> "")

    End Function

    Instead of finding the file, i want it to find the PC, because, although the PC is connected, the file might not be at the location specified so it errors, and i want TWO different error messages. 1 saying the file is not at location, and 1 saying the computer is unable to be located. Can anyone help?

    Comment

    Working...