简体   繁体   中英

How to tell if a network adapter is removable on Windows

How can I tell if a given network adapter retrieved through the Win32 GetAdaptersInfo() or GetAdaptersAddresses() functions is a removable one, like USB, SmartCard, etc?

The documentation for these functions does not seem to contain any means of getting that information, so I'm assuming I have to go ask Windows for each device I find whether it is removable in some way.

What would you suggest?

If you think about it then all adapters are removable (eg PCI, USB, Virtual, etc) Even an in-built NIC can usually be disabled in the BIOS.

What you really want to know is the 'interface type' of each adapter. This information can be found in caption property of the Win32_NetworkAdapterConfiguration Class. You could use this (with other information from the class) to work out how each device is connected to the machine and if it is in use.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT Caption, IPEnabled FROM Win32_NetworkAdapterConfiguration",,48) 
For Each objItem in colItems 
    Wscript.Echo objItem.IPEnabled & " " & objItem.Caption
Next

Also, the Win32_NetworkAdapterConfiguration is very useful for the IPEnabled property as it lets you see if TCP/IP is bound and enabled on the adapter.

Here is an example output

False [00000001] 1394 Net Adapter
False [00000002] RAS Async Adapter
False [00000003] WAN Miniport (L2TP)
False [00000004] WAN Miniport (PPTP)
False [00000005] WAN Miniport (PPPOE)
False [00000006] Direct Parallel
False [00000007] WAN Miniport (IP)
False [00000008] Packet Scheduler Miniport
True [00000009] Wireless-B PCI Adapter
False [00000010] Packet Scheduler Miniport
False [00000011] Cisco AnyConnect VPN Virtual Miniport Adapter for Windows
False [00000012] Packet Scheduler Miniport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM