I know that I could use Windows PowerShell
Get-netadapter|select Name, ndisversion
to pipe the results out to a text file, and parse the data from there, but that's sort of hacky. I was wondering if there's a way to get the same info using something more direct? i.e. WMI or a Framework class, etc.? I've Googled, but came up empty-handed.
All the NetAdapter powershell cmdlets are thin wrappers over WMI objects. So you can indeed use the Microsoft.Management.Infrastructure
namespace directly.
In this case, you'd enumerate instances of root\standardcimv2\MSFT_NetAdapter
to look at their Name
and DriverMajorNdisVersion
fields.
This isn't a complete tutorial on the MI APIs, but here's a pseudocode sketch of the idea:
var session = CimSession.Create(. . .);
foreach (var instance in session.EnumerateInstances(@"root\standardcimv2", "MSFT_NetAdapter")) {
var name = instance.CimInstanceProperties["Name"].Value as string;
var major = instance.CimInstanceProperties["DriverMajorNdisVersion"].Value as byte;
WriteLine($"{name}: {major}.{minor}");
}