参考如下程序<br>Function MyPing(const Host:string):boolean;<br>var<br> CmdLinePChar:array[0..120] of char;<br> StartUpInfo:TStartUpInfo;<br> ProcessInfo:TProcessInformation;<br> HOutput:THandle;<br> StringList:TStringList;<br> TempFileName:String;<br> i:integer;<br>begin<br> Result:=false;<br> Screen.Cursor:=crHourGlass;<br> StringList:=TStringList.Create;<br> try<br> TempFileName:=ExtractFilePath(application.ExeName)+'tempfile.tmp';<br> HOutput:=FileCreate(TempFileName);<br> if HOutput<0 then<br> exit;<br> StrPCopy(CmdLinePChar,'Ping.exe'+Host);<br> FillChar(StartUpInfo,sizeof(StartUpInfo),#0);<br> with StartUpInfo do<br> begin<br> cb:=sizeof(StartUpInfo);<br> dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;<br> wShowWindow:=SW_HIDE;<br> hstdOutput:=HOutput;<br> end;<br> if CreateProcess(nil,CmdLinePChar,nil,nil,True,0,nil,nil,StartUpInfo,ProcessInfo) then<br> begin<br> WaitForSingleObject(Processinfo.hProcess,INFINITE);<br> FileClose(HOutput);<br> end<br> else<br> begin<br> FileClose(HOutput);<br> exit;<br> end;<br> StringList.LoadFromFile(TempFileName);<br> DeleteFile(TempFileName);<br> for i:=1 to StringList.Count-1 do<br> begin<br> if pos('Reply from',StringList)>=1 then<br> begin<br> Result:=true;<br> break;<br> end;<br> end;<br> finally<br> screen.Cursor:=crDefault;<br> form1.edit1.text:=stringlist;<br> StringList.Free;<br><br> end;<br><br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>MyPing(' 172.18.128.1');<br>end;