在网络探索者1.1(qsilence@sina.com)中挖来的一个函数:<br>RunDosCommand('ping.exe ' + 参数, RichEdit1.Lines);<br>=============================================================<br>procedure RunDosCommand(Command : string; Output : TStrings);<br>var<br> hReadPipe : THandle;<br> hWritePipe : THandle;<br> SI : TStartUpInfo;<br> PI : TProcessInformation;<br> SA : TSecurityAttributes;<br>// SD : TSecurityDescriptor;<br> BytesRead : DWORD;<br> Dest : array[0..1023] of char;<br> CmdLine : array[0..512] of char;<br> TmpList : TStringList;<br> Avail, ExitCode, wrResult : DWORD;<br> osVer : TOSVERSIONINFO;<br> tmpstr :AnsiString;<br>begin<br> osVer.dwOSVersionInfoSize := Sizeof(TOSVERSIONINFO);<br> GetVersionEX(osVer);<br><br> if osVer.dwPlatformId = VER_PLATFORM_WIN32_NT then<br> begin<br>// InitializeSecurityDescriptor(@SD, SECURITY_DESCRIPTOR_REVISION);<br>// SetSecurityDescriptorDacl(@SD, True, nil, False);<br> SA.nLength := SizeOf(SA);<br> SA.lpSecurityDescriptor := nil;//@SD;<br> SA.bInheritHandle := True;<br> CreatePipe(hReadPipe, hWritePipe, @SA, 0);<br> end<br> else<br> CreatePipe(hReadPipe, hWritePipe, nil, 1024);<br> try<br> Screen.Cursor := crHourglass;<br> FillChar(SI, SizeOf(SI), 0);<br> SI.cb := SizeOf(TStartUpInfo);<br> SI.wShowWindow := SW_HIDE;<br> SI.dwFlags := STARTF_USESHOWWINDOW;<br> SI.dwFlags := SI.dwFlags or STARTF_USESTDHANDLES;<br> SI.hStdOutput := hWritePipe;<br> SI.hStdError := hWritePipe;<br> StrPCopy(CmdLine, Command);<br> if CreateProcess(nil, CmdLine, nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil, SI, PI) then<br> begin<br> ExitCode := 0;<br> while ExitCode = 0 do<br> begin<br> wrResult := WaitForSingleObject(PI.hProcess, 500);<br>// if PeekNamedPipe(hReadPipe, nil, 0, nil, @Avail, nil) then<br> if PeekNamedPipe(hReadPipe, @Dest[0], 1024, @Avail, nil, nil) then<br> begin<br> if Avail > 0 then<br> begin<br> TmpList := TStringList.Create;<br> try<br> FillChar(Dest, SizeOf(Dest), 0);<br> ReadFile(hReadPipe, Dest[0], Avail, BytesRead, nil);<br> TmpStr := Copy(Dest,0 , BytesRead-1);<br> TmpList.Text := TmpStr;<br> Output.AddStrings(TmpList);<br> finally<br> TmpList.Free;<br> end;<br> end;<br> end;<br> if wrResult <> WAIT_TIMEOUT then ExitCode := 1;<br> end;<br> GetExitCodeProcess(PI.hProcess, ExitCode);<br> CloseHandle(PI.hProcess);<br> CloseHandle(PI.hThread);<br> end;<br> finally<br> CloseHandle(hReadPipe);<br> CloseHandle(hWritePipe);<br> Screen.Cursor := crDefault;<br> end;<br>end;<br>