为何下面这函数不能正确的返回正确值,我在CMD中能够PING通对方,而用次函数却不返回正确的值!~急啊!~谢谢各位了,小弟感激不尽啊!~
或者谁有好的代码也贴上来给我啊,必须要能够从PING命令中得到返回值,谢谢!~Function MyPing(const Host:string):boolean;
var
  CmdLinePChar:array[0..120] of char;
  StartUpInfo:TStartUpInfo;
  ProcessInfo:TProcessInformation;
  HOutput:THandle;
  StringList:TStringList;
  TempFileName:String;
  i:integer;
begin
  Result:=false;
  Screen.Cursor:=crHourGlass;
  StringList:=TStringList.Create;
  try
    TempFileName:=ExtractFilePath(application.ExeName)+'tempfile.tmp';
    HOutput:=FileCreate(TempFileName);
    if HOutput<0 then
      exit;
    StrPCopy(CmdLinePChar,'Ping.exe'+Host);
    FillChar(StartUpInfo,sizeof(StartUpInfo),#0);
    with StartUpInfo do
    begin
      cb:=sizeof(StartUpInfo);
      dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
      wShowWindow:=SW_HIDE;
      hstdOutput:=HOutput;
    end;
    if CreateProcess(nil,CmdLinePChar,nil,nil,True,0,nil,nil,StartUpInfo,ProcessInfo) then
    begin
      WaitForSingleObject(Processinfo.hProcess,INFINITE);
      FileClose(HOutput);
    end
    else
    begin
      FileClose(HOutput);
      exit;
    end;
  StringList.LoadFromFile(TempFileName);
  DeleteFile(TempFileName);
  for i:=1 to StringList.Count-1 do
  begin
    if pos('Reply from',StringList[i])>=1 then
    begin
      Result:=true;
      break;
    end;
  end;
  finally
  screen.Cursor:=crDefault;
  form1.edit1.text:=stringlist[i];
  StringList.Free;  end;