Final demonstration batch file showing the difference between ConfigManagerErrorCode (correct) and NetEnabled (incorrect). I'm putting this in my "bag of tricks" batch file folder, posting here for posterity. I'm also going to be incorporating the ConfigManagerErrorCode=22 thing into the original C# program that I'm working on.

Thanks again!



Code:
@echo off

::
::   ------------------------------------
::   GET LIST OF ENABLED OR DISABLED NICS
::   ------------------------------------
::
::   For WMI, you soon discover that the parameter
::   "NetEnabled" is a bad field, that parameter does
::   not list which NICS are enabled, it lists which
::   nics are connected. So how to determine if they
::   are enabled or not?
::
::   Turns out you have to look at a different field,
::   the ConfigManagerErrorCode, instead. If that is
::   22 then the device is disabled.
::
::   Thanks to Christian ("Shonky") on the EmpegBBS
::   for finding this out!
::
::


set filename="%temp%\ListOfEnabledDisabledNics.txt"
set tempfilename="%temp%\TempListOfEnabledDisabledNics.txt"

echo List of NICs on this computer which are DISABLED or ENABLED. > %filename%
echo:  >> %filename%
echo Note: Do not depend on the NetEnabled field, it is not true. >> %filename%
echo Look at ConfigManagerErrorCode instead. "22" means "Disabled". >> %filename%
echo: >> %filename%
echo: >> %filename%
echo --------- >> %filename%
echo DISABLED: >> %filename%
echo --------- >> %filename%
echo: >> %filename%

:: The command that actually lists the NICs. This is the list of the ones "equal to 22" which is the ones that are disabled.
:: NetConnectionID is the friendly name that you see in NCPA.CPL, only show ones where that value is not blank.
wmic NIC where(NetConnectionID!=NULL AND ConfigManagerErrorCode=22)get NetConnectionID,NetEnabled,ConfigManagerErrorCode,Description > %tempfilename% 2>&1

:: Filter out the unicode from the WMIC output (why the hell did they make it output in unicode?)
:: NICE TRICK: The DOS "Type" command filters out unicode.
type %tempfilename% >> %filename%


echo: >> %filename%
echo: >> %filename%
echo --------- >> %filename%
echo ENABLED:  >> %filename%
echo --------- >> %filename%
echo: >> %filename%

:: This is the "not equal to 22" which is the ones that are enabled or otherwise not explicitly disabled.
wmic NIC where(NetConnectionID!=NULL AND ConfigManagerErrorCode!=22)get NetConnectionID,NetEnabled,ConfigManagerErrorCode,Description > %tempfilename% 2>&1
type %tempfilename% >> %filename%


echo: >> %filename%


:: Display the results in Notepad.
start "List of NICS" notepad.exe %filename%

_________________________
Tony Fabris