views:

424

answers:

1

Hello, community!

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?

+1  A: 

Hi,

If you think about it then all adapters are removable (e.g. 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
Fraser
Hi Fraser, thanks a lot. However, this seems to tell me if an adapter is "IPEnabled", but not if it is removable. Am I missing something?
Carl Seleborg
Please see the edits in my answer...
Fraser
Oh, you mean looking for "PCI", "WAN", "VPN", etc.? Is this the "safe" way to go?
Carl Seleborg
I see your point about "removable". I actually mean the same as when talking about removable storage devices. Removable devices are often associated with other use cases, and change the assumptions. But thanks for your response. +1
Carl Seleborg
Removeable storage is compleatly different as anything not on the BUS is classed as a device with removeable storage. This however has nothing at all to do with network adapters because they are not storage devices (even if they happen to be on one, like a USB stick...)
Fraser