编译通过。自已看,。。。<br>procedure TForm1.Button2Click(Sender:TObject);<br>var<br> hWindow :THandle;<br> i :integer;<br> ping :string;<br>begin<br> ping:='ping 127.0.0.1';<br> winexec('cmd.exe',SW_NORMAL);<br> hWindow:=FindWindow('ConsoleWindowClass',nil);<br> if hWindow=0 then<br> begin<br> ShowMessage('未找到指定窗口');<br> Exit;<br> end<br> else<br> begin<br> SetForegroundWindow(hWindow);<br> SetActiveWindow(hWindow);<br> for i:=1 to Length(ping) do SendMessage(hWindow,WM_CHAR,Ord(ping),1);<br> <br> end;<br>end;