Wow, this one should be really easy, but it turns out it's not, thanks to Microsoft's API having an incorrect information return from one of their API functions.

I'm having a programming problem and I'm wondering if anyone on the BBS has seen a solution to this one?

Requirement: Programatically find out which network interfaces on the system (Wired, WiFi, Mobile Broadband, Bluetooth, 1394, whatever) are ENABLED or DISABLED (*not* connected/disconnected which must be ignored in this case, but rather, we need to know enabled or disabled).

In other words, if I'm in the Windows GUI and I run the program:
NCPA.CPL
...which brings up the network adapters control panel, I see a list of network adapters including all of the Wired, Bluetooth, WiFi, Mobile Broadband, and whatnot adapters. I can right-click on any of them and select DISABLE or I can select ENABLE. When one is disabled it is grayed out. In addition to the level of whether they are enabled or disabled, any given one of them can be connected or disconnected (or in the process of connecting).

What I want to know is, regardless of whether they are disconnected or connected, I want to know, from any programming language (DOS script, C, C#, powershell, whatever, but preferably C# because it's what I'm working in right now) which ones are ENABLED or DISABLED. I need a list. That list should be every network adapter on the system, and whether, at the moment I run the function, their current state is ENABLED or DISABLED.

Oh my God, do you have any idea how hard that is? You'd think it's easy. There are a thousand things on the internet saying "oh sure just do this...." Guess what? They're all WRONG because they all harken back to the same WMI interface command, and it's WRONG. IT LIES. Here's what they all boil back down to: Win32_NetworkAdapter class, property: NetEnabled

If you look at the dox for the NetEnabled property it says:
Quote:

NetEnabled
Data type: boolean
Access type: Read-only
Indicates whether the adapter is enabled or not. If True, the adapter is enabled. You can enable or disable the NIC by using the Enable and Disable methods.

THIS IS A LIE.

It only responds with the adapter's connected state not its enabled/disabled state. For example, if the adapter is enabled, but not connected to the network, this property will return FALSE.

What's interesting is that the Enable and Disable methods indeed disable and enable the adapter as mentioned in the dox above, but the NetEnabled property has nothing to do with that. For example, you can have five network adapters, all of them disconnected (but enabled) and NetEnabled will be "FALSE" for all of them. Run ".Disable" on one of them and it will go gray in the network control panel, but all five will still read NetEnabled="FALSE". Run ".Enable" on the one you disabled, and it will ungray in the network control panel, but it will still read NetEnabled="FALSE" when queried with WMI.

Okay, so how do I work around it? I've tried:

- In .NET in C#, using System.Net.NetworkInformation namespace NetworkInterface class. This can get me a property of "OperationalStatus" which is "Up" or "Down" but again this is useless since it's only "Up" if it's connected.

- The DOS command "netsh interface show interface". This WORKS and shows the correct "Admin State" of the interface as being enabled or disabled. However it's only for wired and Wifi networks, and does not include the other types of networks such as Mobile Broadband, which happens to be hyper-critical for my particular application.

- The DOS command "wmic nic get NetConnectionID". This lists all network adapter names including the disabled ones. No information about disabled/enabled.

- The DOS command "wmic nic get > somelistfile.txt". This lists all network adapters and all their WMI properties to a file. None of the columns in that file indicate disabled/enabled state. There is a column for our old friend NetEnabled which is still lying like a rug, as above.

- Any variations in various languages I've seen all come back down to that WMI "NetEnabled" property. I.e., a lie.

Any ideas? Has anyone run into this before?
_________________________
Tony Fabris