哦 抱歉 昨天晚上有点晕,把原来的东西就发上来了,有点错误
下面的应该可以用
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, shellapi;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
exehwnd:HWND;
addstr: string;
begin //指定IP
addstr:='interface ip set address '+'本地连接'+' static '+'10.5.15.60'+' '+'255.255.255.0'+' '+'10.5.15.1'+' 1';
exehwnd:=shellexecute(application.Handle,'open',pchar('netsh'),pchar(addstr),nil,sw_hide);
waitforsingleobject(exeHwnd,infinite);
messagebox(application.Handle,'修改完成。','提示',mb_ok);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
exehwnd:HWND;
addstr: string;
begin //自动获取IP
addstr:='interface ip set address '+'本地连接'+' source=dhcp';
exehwnd:=shellexecute(application.Handle,'open',pchar('netsh'),pchar(addstr),nil,sw_hide);
waitforsingleobject(exeHwnd,infinite);
messagebox(application.Handle,'修改完成。','提示',mb_ok);
end;
end.