Reading NDIS miniport statistic value

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To read NDIS (Network Driver Interface Specification) miniport statistic values programmatically, you can use the Windows Management Instrumentation (WMI) API. Here's an example in C#:

csharp
using System;
using System.Management;

class Program
{
static void Main()
{
try
{
// Query WMI for the NDIS miniport statistics
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSNdis_Statistics");
ManagementObjectCollection queryResults = searcher.Get();

// Iterate over the query results
foreach (ManagementObject queryResult in queryResults)
{
// Read the statistic value properties
string statisticName = queryResult["Name"].ToString();
ulong statisticValue = (ulong)queryResult["Data"];

// Display the statistic value
Console.WriteLine($"{statisticName}: {statisticValue}");
}
}
catch (ManagementException ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}

In this example, the code uses the ManagementObjectSearcher class to execute a WMI query targeting the MSNdis_Statistics class. This class provides various statistics for NDIS miniports. The code retrieves the statistic name and value from each query result and displays them.

Compile and run the code to see the NDIS miniport statistics and their corresponding values.

Note that this code requires administrative privileges to access the WMI information.