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.
Re: another ping question run on a network
Here code for You
You can use API to handle Process
VB Code:
Public Const STATUS_PENDING = &H103&
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hFile As Long) As Long
Public Sub subStartAndWait(cmdline As String)
Dim hProcess As Long
Dim ProcessId As Long
Dim exitCode As Long
On Local Error GoTo ErrorLine
ProcessId = Shell(cmdline, 1)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, exitCode)
DoEvents
Loop While exitCode = STATUS_PENDING
Call CloseHandle(hProcess)
MsgBox "The shelled process " & cmdline & " has ended."
ErrorLine:
End Sub
oh1mie/Vic