Dim pid As Long
pid = Shell("cmd.exe /C Ping " & Text1.Text & " > c:\r.txt", vbHide)
' 提示
Text2.Text = "正在执行Ping " & Text1.Text & " ..."
'等待Shell执行结束
Dim hProc As Long
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
Dim ExitCode As Long
Do
Call GetExitCodeProcess(hProc, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
'清空,准备显示结果
Text2.Text = ""
'打开 C:\r.txt文件
Open "c:\r.txt" For Input As #1
Dim strLine As String
Do Until EOF(1)
Line Input #1, strLine
'显示执行结果
Text2.Text = Text2.Text & strLine & vbNewLine
Loop
'关闭文件
Close #1
'删除C:\r.txt
On Error Resume Next
Kill "c:\r.txt"