unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,filectrl, ExtCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    StaticText1: TStaticText;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
var
 temp:string;
{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Clear ;
if fileexists(temp) then
  deletefile(temp);
//每次查询前将前次结果清除,上面三个清空或删除语句保证了多次查询时每次得到的都是最新查询的结果。
winexec(pchar('command.com /C ipconfig /all >'+temp),sw_hide);
//执行命令将查询结果存到临时文件temp,sw_hide指定将DOS界面隐藏。
while not fileexists(temp) do
  sleep(1000);
//为了临时文件的建立等待1秒种try
 memo1.lines.loadfromfile(temp);
except
//此处不写任何代码,即关闭任何异常。
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.Clear;
temp:='c:\temp.txt';
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if fileexists(temp) then
 deletefile(temp);
end;end.