本帖最后由 飘云 于 2011-5-1 16:04 编辑
用api函数GetIfEntry来获取网卡信息到MIB_IFROW结构中,然后MIB_IFROW结构中的dwAdminStatus项即网卡状态,1启用,2禁用,最后一项bDescr是描述网卡的,便于用户识别网卡。
大概的写了下,我这段代码的前提是需要用户知道网卡名,当然也可以通过遍历网络连接然后让用户选择
Dim $a=1,$network="Broadcom 802.11g Network Adapter"
$MIB_IFROW = DllStructCreate("wchar wszName[256];dword dwIndex;dword dwType;dword dwMtu;dword dwSpeed;dword dwPhysAddrLen;char bPhysAddr[8];dword dwAdminStatus;dword dwOperStatus;dword dwLastChange;dword dwInOctets;dword dwInUcastPkts;dword dwInNUcastPkts;dword dwInDiscards;dword dwInErrors;dword dwInUnknownProtos;dword dwOutOctets;dword dwOutUcastPkts;dword dwOutNUcastPkts;dword dwOutDiscards;dword dwOutErrors;dword dwOutQLen;dword dwDescrLen;char bDescr[256]")
While 1
DllStructSetData($MIB_IFROW, "dwIndex", $a);第三个参数是指定想要检测的网卡序号给dwIndex元素
DllCall("iphlpapi.dll", "dword", "GetIfEntry", "ptr", DllStructGetPtr($MIB_IFROW));调用GetIfEntry将此指定网卡的信息写入数据结构$MIB_IFROW中
If DllStructGetData($MIB_IFROW,"bDescr")=$network Or $a>200 Then ExitLoop
$a+=1
WEnd
If $a>200 Then
MsgBox(0,"","未发现网卡【"&$network&"】")
ElseIf DllStructGetData($MIB_IFROW,"dwAdminStatus")=1 Then
MsgBox(0,"","网卡【"&$network&"】已启用")
ElseIf DllStructGetData($MIB_IFROW,"dwAdminStatus")=2 Then
MsgBox(0,"","网卡【"&$network&"】已禁用")
EndIf
|