请问怎样编写一个程序,让它能在WIN98中禁用网卡?(100分)

  • 主题发起人 主题发起人 hundred007
  • 开始时间 开始时间
H

hundred007

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样编写一个程序,让它能在WIN98中禁用网卡?[8D]
 
方法一:
用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.

方法二:
ftp://delphi-jedi.org/api/IPHlpAPI.zip

里面包括几乎所有的网卡,ip,dns相关的代码和.h头文件的delphi译本,附有范例程序
 
AnsiString Local;
LPCSTR lLocal;
Local=txtLocalName=Text;
lLocal=Local.c_str;
try
{
WNetCancenConnection2(lLocal,CONNECT_UPDATE_PROFILE,true);
}
catch(Exception &exception)
{
Application->ShowException(&exception);
}
 
使用:ftp://delphi-jedi.org/api/IPHlpAPI.zip
关闭所有网卡:
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;
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;

 
以上方法不能真正意义上的禁用网卡,确实//IP不能访问计算机的默认共享了,但是通过//主机名仍能够访问计算机的默认共享

如需要 物理禁用网卡 的程序,留下MAIL
 
我想能禁用IP通讯,就已经解决问题了,物理禁用网卡没有多大意义,
但我想知道,请xzs@sdu.edu.cn, 谢谢。
 
to pihome:
大侠!你有物理禁用网卡 的程序?我也想要看看
chensoft@etang.com
 
后退
顶部