因此
首先看一下原理
Window的netsh命令通過創建和調用記錄網絡配置的文本文件即可修改網絡配置
Netsh interface dump > 相對路徑\ netcfg
這條命令可以將計算機現有的網絡配置保存在netcfg
Netsh
這條命令即可將netcfg
基於以上的兩條命令
如上圖所示
網絡設置
代碼如下
procedure TForm BitBtn Click(Sender: TObject); // 局域網 按鈕的單擊事件
begin
FileAppendProc ();
RadioButton Checked:=true;
end;
procedure TForm FileAppendProc (); //保存文件的函數
var NetFile : TextFile;
NetFilename : string;
FileAppend tempStr : string;
begin
NetFilename := netcfg txt ;
FileAppend :=S +MaskEdit Text+S +MaskEdit Text+S +MaskEdit Text+S +S ;
//MessageDlg( This is commend +FileAppend mtInformation [mbOK] );
AssignFile(Netfile net txt ); //net txt文件要放在應用程序的同一目錄中
Reset(NetFile);
begin
try
Memo Lines Text:= ;
while not Eof(NetFile) do
begin
Readln(NetFile tempStr);
Memo Lines Add(tempStr) ;
end;
finally
begin
CloseFile(NetFile);
end;
end;
AssignFile(Netfile NetFilename);
Rewrite(NetFile);
try
Writeln(NetFile );
finally
CloseFile(NetFile);
end;
Memo Lines Add(FileAppend);
Memo Lines SaveToFile(NetFilename);
end;
end;
procedure TForm MaskEdit Exit(Sender: TObject); //IP地址輸入出錯處理
var ip ip ip ip : Integer;
begin
if (copy(MaskEdit Text )= ) or (copy(MaskEdit Text )= ) or (copy(MaskEdit Text )= ) or (copy(MaskEdit Text )= ) then
begin
showmessage( 請注意 不能有空域值 ) ;
MaskEdit SetFocus;
end;
if (copy(MaskEdit Text )<> ) and (copy(MaskEdit Text )<> ) and (copy(MaskEdit Text )<> ) and (copy(MaskEdit Text )<> ) then
begin
ip :=strtoint(trim(copy(MaskEdit Text )));
ip :=strtoint(trim(copy(MaskEdit Text )));
ip :=strtoint(trim(copy(MaskEdit Text )));
ip :=strtoint(trim(copy(MaskEdit Text )));
if (ip < ) or (ip > ) or (ip < ) or (ip > ) or(ip < ) or (ip > ) or (ip < ) or (ip > ) then
begin
showmessage( 您的輸入不正確 請重新輸入! );
MaskEdit SetFocus;
end;
end;
end;
右側網絡替換功能的編制相對簡單些
procedure TForm Button Click(Sender: TObject); // 確定 按鈕的單擊事件
begin
if RadioButton Checked then winexec( netsh f netcfg txt sw_normal) ;
if RadioButton Checked then winexec( netsh f netcfg txt sw_normal) ;
end;
這樣
From:http://tw.wingwit.com/Article/program/Delphi/201311/24934.html