Wednesday 29 February 2012

Explore networking configuration with INetCfg interface

Current configuration of network adapters in Windows OS can be explored from Network Connections (Start -> Control Panel -> Network and Sharing Center -> Change Adapter Settings). Selecting Properties from a right click context menu for chosen connection displays a dialog box which contains Networking tab. It contains the name of the network adapter used by this connection and, below it, a list of network features bound to the adapter. Those features are:

  • network clients (identified with a COM class with GUID GUID_DEVCLASS_NETCLIENT)
  • network services (GUID_DEVCLASS_NETSERVICE)
  • network protocols (transports) (GUID_DEVCLASS_NETTRANS)

(Adapters are identified with a COM class with GUID GUID_DEVCLASS_NET.)

You can install or uninstall, enable or disable these features manually from that dialog box.

In order to view or modify these networking configuration programmatically we can use a family of COM objects starting with a root one which implements INetCfg interface. When we acquire (pointer to) this object, we can query it for all other interfaces and call methods on them. Common name for these methods is INetCfg API. They are all implemented in Netcfgx.dll. This dll basically contains Network Configuration COM Objects and can be found in C:\Windows\System32.

Following code shows how to use INetCfg API in order to display all network adapters, clients, transports and services. For each client, transport and service we check which adapter it is bound to.



Output:




Enumerating GUID_DEVCLASS_NET class:

Network card (adapter) 1:
        Display name: VirtualBox Host-Only Ethernet Adapter
        Bind name: {0B904F29-FBC7-452E-B502-038521DC4212}
        Characteristics: 4
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: sun_vboxnetadp

Network card (adapter) 2:
        Display name: Microsoft ISATAP Adapter #4
        Bind name: {EAAB95CA-6285-4DE9-AF45-8643E8662958}
        Characteristics: 9
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: Microsoft ISATAP Adapter Driver
        ID: *isatap

Network card (adapter) 3:
        Display name: Microsoft Windows Mobile Remote Adapter
        Bind name: {2C42503C-D28B-4A6F-9A3B-88C806CDDE3B}
        Characteristics: 132
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: usb\class_ef&subclass_01&prot_01

Network card (adapter) 4:
        Display name: Microsoft ISATAP Adapter #2
        Bind name: {05388434-DF29-4E65-99C1-557E0E276171}
        Characteristics: 9
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: Microsoft ISATAP Adapter Driver
        ID: *isatap

Network card (adapter) 5:
        Display name: Microsoft ISATAP Adapter #3
        Bind name: {F41C92AB-9451-437B-B7E8-713CE75F76B4}
        Characteristics: 9
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: Microsoft ISATAP Adapter Driver
        ID: *isatap

Network card (adapter) 6:
        Display name: WAN Miniport (IKEv2)
        Bind name: {96704964-C9AC-4D9E-B07E-CB777DBA8DD9}
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_agilevpnminiport

Network card (adapter) 7:
        Display name: Apollo NDIS Driver for Windows Vista/7
        Bind name: {65A8E0D2-5990-402A-8B9D-12527C3813C6}
        Characteristics: 129
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: This protocol allows the apollo emulator to act as ;
        ID: brandapolloemulator

Network card (adapter) 8:
        Display name: Teredo Tunneling Pseudo-Interface
        Bind name: {D8CDC497-340C-4AF0-8B3F-12ECE377706D}
        Characteristics: 9
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: Microsoft Teredo Tunneling Adapter
        ID: *teredo

Network card (adapter) 9:
        Display name: Microsoft ISATAP Adapter
        Bind name: {8A9C39F5-6704-4E11-91CE-122BFA7150E9}
        Characteristics: 9
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text: Microsoft ISATAP Adapter Driver
        ID: *isatap

Network card (adapter) 10:
        Display name: Intel(R) 82566DC Gigabit Network Connection
        Bind name: {B05DCEC3-9E0E-499C-8EA0-F86503FDA39B}
        Characteristics: 132
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: pci\ven_8086&dev_104b

Network card (adapter) 11:
        Display name: RAS Async Adapter
        Bind name: {E2F8A220-AF88-446C-9A55-453E58DD3A33}
        Characteristics: 42
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: sw\{eeab7790-c514-11d1-b42b-00805fc1270e}

Network card (adapter) 12:
        Display name: WAN Miniport (IP)
        Bind name: NdisWanIp
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_ndiswanip

Network card (adapter) 13:
        Display name: WAN Miniport (Network Monitor)
        Bind name: NdisWanBh
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_ndiswanbh

Network card (adapter) 14:
        Display name: WAN Miniport (IPv6)
        Bind name: NdisWanIpv6
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_ndiswanipv6

Network card (adapter) 15:
        Display name: WAN Miniport (PPPOE)
        Bind name: {DB2B4279-B5CF-4626-9DBA-32D0ECE44C87}
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_pppoeminiport

Network card (adapter) 16:
        Display name: WAN Miniport (PPTP)
        Bind name: {C0DE3E38-8BA7-479F-8B75-833F294C5AA8}
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_pptpminiport

Network card (adapter) 17:
        Display name: WAN Miniport (L2TP)
        Bind name: {483C9FF8-503D-414B-B402-E4C1F1F568CB}
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_l2tpminiport

Network card (adapter) 18:
        Display name: WAN Miniport (SSTP)
        Bind name: {E28D896F-9EA8-433A-9C10-66C97C19A921}
        Characteristics: 41
        Class GUID: 1295444338-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_sstpminiport



Enumerating GUID_DEVCLASS_NETCLIENT class:

Network client 1:
        Display name: Client for Microsoft Networks
        Bind name: LanmanWorkstation
        Characteristics: 128
        Class GUID: 1295444339-58149-4558-3210004
        Device Status: 0
        Help Text: Allows your computer to access resources on a Microsoft netwo
rk.
        ID: ms_msclient
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection



Enumerating GUID_DEVCLASS_NETTRANS class:

Network transport 1:
        Display name: AgileVpn based VPN
        Bind name: msagilevpn
        Characteristics: 56
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Allows you to securely connect to a private network using the
 Internet.
        ID: ms_agilevpn

Network transport 2:
        Display name: Microsoft TCP/IP version 6 - Tunnels
        Bind name: TCPIP6TUNNEL
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_tcpip6_tunnel
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter

Network transport 3:
        Display name: Internet Protocol (TCP/IP) - Tunnels
        Bind name: TCPIPTUNNEL
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_tcpip_tunnel

Network transport 4:
        Display name: Microsoft NetbiosSmb
        Bind name: Smb
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_smb
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 5:
        Display name: Remote Access IP ARP Driver
        Bind name: Wanarp
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_wanarp
           Bound to: WAN Miniport (IP)

Network transport 6:
        Display name: Message-oriented TCP/IP Protocol (SMB session)
        Bind name: NetbiosSmb
        Characteristics: 56
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_netbt_smb

Network transport 7:
        Display name: WINS Client(TCP/IP) Protocol
        Bind name: NetBT
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_netbt
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 8:
        Display name: Internet Protocol Version 6 (TCP/IPv6)
        Bind name: Tcpip6
        Characteristics: 160
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: TCP/IP version 6. The latest version of the internet protocol
 that provides communication across diverse interconnected networks.
        ID: ms_tcpip6
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 9:
        Display name: Internet Protocol Version 4 (TCP/IPv4)
        Bind name: Tcpip
        Characteristics: 160
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Transmission Control Protocol/Internet Protocol. The default
wide area network protocol that provides communication across diverse interconne
cted networks.
        ID: ms_tcpip
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 10:
        Display name: Link-Layer Topology Discovery Mapper I/O Driver
        Bind name: lltdio
        Characteristics: 0
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Used to discover and locate other PCs, devices, and network i
nfrastructure components on the network.  Also used to determine network bandwid
th.
        ID: ms_lltdio
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 11:
        Display name: Link-Layer Topology Discovery Responder
        Bind name: rspndr
        Characteristics: 0
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Allows this PC to be discovered and located on the network.
        ID: ms_rspndr
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 12:
        Display name: Remote Access IPv6 ARP Driver
        Bind name: Wanarpv6
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_wanarpv6
           Bound to: WAN Miniport (IPv6)

Network transport 13:
        Display name: Point to Point Protocol Over Ethernet
        Bind name: RasPppoe
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Provides the abilitiy to connect a host to a Remote Access Co
ncentrator that supports RFC2516.
        ID: ms_pppoe
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network transport 14:
        Display name: Point to Point Tunneling Protocol
        Bind name: mspptp
        Characteristics: 56
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Allows you to securely connect to a private network using the
 Internet.
        ID: ms_pptp

Network transport 15:
        Display name: Layer 2 Tunneling Protocol
        Bind name: msl2tp
        Characteristics: 56
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Allows you to securely connect to a private network using the
 Internet.
        ID: ms_l2tp

Network transport 16:
        Display name: Remote Access NDIS WAN Driver
        Bind name: NdisWan
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_ndiswan
           Bound to: WAN Miniport (IKEv2)
           Bound to: RAS Async Adapter
           Bound to: WAN Miniport (PPPOE)
           Bound to: WAN Miniport (PPTP)
           Bound to: WAN Miniport (L2TP)
           Bound to: WAN Miniport (SSTP)

Network transport 17:
        Display name: SSTP based VPN
        Bind name: mssstp
        Characteristics: 56
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text: Allows you to securely connect to a private network using the
 Internet.
        ID: ms_sstp

Network transport 18:
        Display name: NDIS Usermode I/O Protocol
        Bind name: Ndisuio
        Characteristics: 40
        Class GUID: 1295444341-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_ndisuio
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection



Enumerating GUID_DEVCLASS_NETSERVICE class:

Network service 1:
        Display name: VirtualBox Bridged Networking Driver
        Bind name: VBoxNetFlt
        Characteristics: 17424
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: VirtualBox Bridged Networking Driver
        ID: sun_vboxnetflt
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network service 2:
        Display name: Apollo Lan Service
        Bind name: Sfilter
        Characteristics: 1040
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Apollo Lan Service
        ID: bc_sfilter

Network service 3:
        Display name: Apollo VLAN Trunk Service
        Bind name: ApVlanIm
        Characteristics: 1040
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Apollo VLAN Trunk Service
        ID: bc_apvlanim

Network service 4:
        Display name: Virtual Machine Network Services
        Bind name: VPCNetS2
        Characteristics: 17552
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Provides networking support for Microsoft virtual machines.
        ID: cntx_vpcnets2
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network service 5:
        Display name: NativeWiFi Filter
        Bind name: NativeWifiP
        Characteristics: 262184
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_nativewifip

Network service 6:
        Display name: NDIS Capture LightWeight Filter
        Bind name: NdisCap
        Characteristics: 262200
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Packet Capture Filter Driver
        ID: ms_ndiscap

Network service 7:
        Display name: QoS Packet Scheduler
        Bind name: Psched
        Characteristics: 262144
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Quality of Service Packet Scheduler.  This component provides
 network traffic control, including rate-of-flow and prioritization services.
        ID: ms_pacer
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection
           Bound to: WAN Miniport (IP)
           Bound to: WAN Miniport (Network Monitor)
           Bound to: WAN Miniport (IPv6)

Network service 8:
        Display name: File and Printer Sharing for Microsoft Networks
        Bind name: LanmanServer
        Characteristics: 0
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: Allows other computers to access resources on your computer u
sing a Microsoft network.
        ID: ms_server
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network service 9:
        Display name: NetBIOS Interface
        Bind name: NetBIOS
        Characteristics: 40
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_netbios
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Microsoft ISATAP Adapter #4
           Bound to: Microsoft Windows Mobile Remote Adapter
           Bound to: Microsoft ISATAP Adapter #2
           Bound to: Microsoft ISATAP Adapter #3
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Teredo Tunneling Pseudo-Interface
           Bound to: Microsoft ISATAP Adapter
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network service 10:
        Display name: WFP Lightweight Filter
        Bind name: WfpLwf
        Characteristics: 262184
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text: WFP Lightweight Filter
        ID: ms_wfplwf
           Bound to: VirtualBox Host-Only Ethernet Adapter
           Bound to: Apollo NDIS Driver for Windows Vista/7
           Bound to: Intel(R) 82566DC Gigabit Network Connection

Network service 11:
        Display name: Steelhead
        Bind name: RemoteAccess
        Characteristics: 40
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_steelhead

Network service 12:
        Display name: Dial-Up Server
        Bind name: msrassrv
        Characteristics: 56
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_rassrv

Network service 13:
        Display name: Remote Access Connection Manager
        Bind name: RasMan
        Characteristics: 40
        Class GUID: 1295444340-58149-4558-3210004
        Device Status: 0
        Help Text:
        ID: ms_rasman

I have omitted here output made by the line marked with (*) as it produces hundreds of lines that list binding paths for a given network device. Here is just one snippet from the full output:

           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\*ISATAP\0003; Enab
led: true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\*ISATAP\0001; Enab
led: true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\*ISATAP\0002; Enab
led: true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\NET\0000; Enabled:
 true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\*TEREDO\0000; Enab
led: true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\*ISATAP\0000; Enab
led: true
           Binding Path: Token = ms_msclient->ms_tcpip6->PCI\VEN_8086&DEV_104B&S
UBSYS_01DB1028&REV_02\3&172E68DD&0&C8; Enabled: true
           Binding Path: Token = ms_msclient->ms_tcpip6->ROOT\NET\0001; Enabled:
 true
           Bound to: Microsoft ISATAP Adapter
           Binding Path: Token = ms_msclient->ms_netbt_smb; Enabled: true
           Binding Path: Token = ms_msclient->ms_netbt->ms_tcpip6->ROOT\*ISATAP\
0003; Enabled: true

INetCfg API supports modifying networking configuration as well (e.g. changing the order of the protocol bindings). Changes can be made only after a lock is acquired. It is possible to search for a particular network item (without iterating through all of them).

Links and References:

Network Configuration Interfaces (MSDN)
Exploring Network Configuration with the INetCfg COM Interface (CodeProject)
Using COM in Your Windows Program (MSDN)
Introduction to Protocols (The Binding Process)

1 comment:

Eko said...

It tremendously helps me!
Have been scratching my head in the past few days. I am in the process of using it through Python. Your example on how to use IEnumNetCfgBindingInterface completely solved my confusion.

Still new in COM here ;)