Thanks to some other helpful StackOverflow questions, I've found a way to query WMI for device drivers. However, it seems to me that the data is being stored in disparate places that don't join together well.
I have a USB-to-serial port cable using FTDI drivers. I can query Win32_SystemDrivers
to determine whether or not the drivers have been installed, like this:
SelectQuery query = new SelectQuery("Win32_SystemDriver");
query.Condition = "Name = 'FTDIBUS'";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection drivers = searcher.Get();
bool installed = (drivers.Count > 0);
But that collection doesn't tell me a thing about version information. So then I discovered I could query Win32_PnPSignedDriver
to find the version of the device driver. So I'm doing something like this:
SelectQuery query = new SelectQuery("Win32_PnPSignedDriver");
query.Condition = "DriverProviderName = 'FTDI'";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection drivers = searcher.Get();
foreach (ManagementBaseObject driverObject in drivers)
{
ManagementObject driver = (ManagementObject)driverObject;
string version = driver["DriverVersion"].ToString();
}
However, that second block of code will only succeed if the cable (device) is actually plugged in. What I'd like to do is to check the version of the installed device driver, regardless of whether or not the device is currently plugged in.
How do I do this?
It seems Win32_SystemDriver class can give you the PathName of the associated driver .sys file.
Example: "\SystemRoot\System32\drivers\afd.sys"
Then you can get the .sys file version with :
String path = @"C:\Windows\System32\drivers\afd.sys"
var myFileVersionInfo = FileVersionInfo.GetVersionInfo(path);
var version = myFileVersionInfo.ProductVersion;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With