方法2:
关闭所有网卡:
procedure TForm1.DisplayInterfaceList;
var
IfTable: PMibIfTable;
Row: TMibIfRow;
Size: ULONG;
I, J: Integer;
S,ss: string;
begin
Size := 0;
if not GetIfTable(nil, Size, True) = ERROR_BUFFER_OVERFLOW then Exit;
IfTable := AllocMem(Size);
try
if GetIfTable(IfTable, Size, True) = ERROR_SUCCESS then
begin
for I := 0 to IfTable^.dwNumEntries - 1 do
begin
ss:='';
Row := IfTable^.Table[I];
ss:=ss+Format('0x%-x ..... ', [Row.dwIndex]);
S := '';
for J := 0 to Row.dwDescrLen - 1 do
S := S + Chr(Row.bDescr[J]);
ss:=ss+s;
Form1.memo1.Lines.Add(ss);
row.dwAdminStatus:=MIB_IF_ADMIN_STATUS_UP;
SetIfEntry(row);
end;
end;
finally
FreeMem(IfTable);
end;
end;
试试行不行啊。不过禁用网卡是比较好的选择。
楼主已有思路了阿,就是先让网卡禁用再启用。
用IphlpApi中的函数
Platform SDK: Internet Protocol Helper
SetIfEntry
Use the SetIfEntry function to set the administrative status of an interface.
DWORD SetIfEntry(
PMIB_IFROW pIfRow
);
Parameters
pIfRow
[in] Pointer to a MIB_IFROW structure. The dwIndex member of this structure specifies the interface on which to set administrative status. The dwAdminStatus member specifies the new administrative status. The dwAdminStatus member can be one of the following values.
Value Meaning
MIB_IF_ADMIN_STATUS_UP The interface is administratively enabled.
MIB_IF_ADMIN_STATUS_DOWN The interface is administratively disabled.
Return Values
If the function succeeds, the return value is NO_ERROR.
If the function fails, use FormatMessage to obtain the message string for the returned error.
Requirements
Windows NT/2000/XP: Included in Windows NT 4.0 SP4 and later.
Windows 95/98/Me: Included in Windows 98 and later.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.