一个我以前写的调用Window的Command的测试程序(就是调用Ping的),改改应该就可以实现你的目标。
unit fTesting;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TfmTest = class(TForm)
btnTest: TButton;
mmTest: TMemo;
edtTest: TEdit;
cmbxTest: TComboBox;
Button1: TButton;
tmrTest: TTimer;
procedure btnTestClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure tmrTestTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmTest: TfmTest;
implementation
{$R *.dfm}
procedure TfmTest.btnTestClick(Sender: TObject);
var
strTmp: String;
begin
strTmp := 'COMMAND.COM /C nbtstat ' + cmbxTest.Text + ' ' + edtTest.Text + ' > $temp%';
WinExec(PChar(strTmp), SW_HIDE);
Sleep(1000);
try
try
mmTest.Lines.LoadFromFile('$temp%');
except
;
end;
finally
DeleteFile('$temp%');
end;
end;
procedure TfmTest.Button1Click(Sender: TObject);
var
strTmp: String;
begin
strTmp := 'command.com /c ping -n 10 ' + edtTest.Text + ' > a.txt';
ShowMessage(strTmp);
WinExec(PChar(strTmp),SW_HIDE);
TmrTest.Enabled := True;
end;
procedure TfmTest.tmrTestTimer(Sender: TObject);
begin
mmTest.Lines.LoadFromFile('a.txt');
end;
end.