Results 1 to 2 of 2

Thread: another ping question run on a network

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    another ping question run on a network

    I have looked at a few of the ping responses and even went to the following site:
    http://www.mvps.org/vbnet/code/netw...gbyhostname.htm
    and created a app which does goes but I am looking for some help.

    I need to ping a box at work every so often and see the 4 returns. Example of the output I am looking for:
    Pinging #.#.#.# with 32 bytes of data:
    Reply from #.#.#.#: bytes=32 time=243ms TTL=243
    Reply from #.#.#.#: bytes=32 time=613ms TTL=243
    Reply from #.#.#.#: bytes=32 time=206ms TTL=243
    Reply from #.#.#.#: bytes=32 time=261ms TTL=243

    If something is not right I usually see 'Request timed out'.

    The nice api code from the html above doesn't return all this for me. Matt Gates did have some code (below) that did work nicely but my problem with that is I have to put a timer on it and wait a certain amount of time (wait for shell to complete) then loop through the output file. Then I can save the output to a archive file.

    Matt Gates code:
    Shell "command.com /c ping " & txtIP.Text & " > C:\ping.txt", 0
    Open "C:\ping.txt" For Input As #1
    txtResults.Text = Input(LOF(1), 1)
    Close #1
    Kill "C:\ping.txt"

    I like the API above but doesn't show enough plus I couldn't get it to work on the network only dialup. Anyone know how to show all the outputs and work on a network?
    If I use the shell does anyone know if I can determine when it (the shell returns back to prompt) finishes so I wouldn't have to use the timer.

    Thanks for any tips/info/help.

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: another ping question run on a network

    Here code for You
    You can use API to handle Process
    VB Code:
    1. Public Const STATUS_PENDING = &H103&
    2. Public Const PROCESS_QUERY_INFORMATION = &H400
    3.  
    4. Public Declare Function GetExitCodeProcess Lib "kernel32" _
    5.     (ByVal hProcess As Long, lpExitCode As Long) As Long
    6.  
    7. Public Declare Function OpenProcess Lib "kernel32" _
    8.  (ByVal dwDesiredAccess As Long, _
    9.   ByVal bInheritHandle As Long, _
    10.   ByVal dwProcessId As Long) As Long
    11.  
    12. Public Declare Function CloseHandle Lib "kernel32" _
    13.    (ByVal hFile As Long) As Long
    14. Public Sub subStartAndWait(cmdline As String)
    15.  
    16.     Dim hProcess  As Long
    17.     Dim ProcessId As Long
    18.     Dim exitCode  As Long
    19.    
    20.     On Local Error GoTo ErrorLine
    21.  
    22.     ProcessId = Shell(cmdline, 1)
    23.     hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
    24.  
    25.     Do
    26.       Call GetExitCodeProcess(hProcess, exitCode)
    27.       DoEvents
    28.     Loop While exitCode = STATUS_PENDING
    29.  
    30.     Call CloseHandle(hProcess)
    31.  
    32.     MsgBox "The shelled process " & cmdline & " has ended."
    33.  
    34. ErrorLine:
    35.  
    36. End Sub
    oh1mie/Vic
    Last edited by oh1mie; Apr 20th, 2002 at 10:23 AM.
    oh1mie/Vic


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width