Way to Detect Device Driver

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
sabinhagen
Posts: 6
Joined: Wed 19. Dec 2018, 03:29

Way to Detect Device Driver

Post by sabinhagen » Wed 16. Jan 2019, 02:16

My WPF application checks for the presence of the necessary DLL files when it starts up, but I don't know how to check whether or not the USB driver has been installed. If the DLL is present, I can read the GetValue function with the PCAN_CHANNEL_VERSION parameter. But I should be able to check for the presence of the Device Driver without the DLL, although I realize this is probably more of a general Windows question.

I think the proper way would be to use System.Management.SelectQuery("Win32_SystemDriver"), what driver name do I query on though? PCAN_USB.sys?

Thanks in advance for any help!!!

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Way to Detect Device Driver

Post by K.Wagner » Wed 16. Jan 2019, 10:54

Hello,

yes, this is a possibility. Though, since you are asking for the driver name, you should use the string "PCAN_USB" instead.

Code: Select all

var searcher = new System.Management.ManagementObjectSearcher(
    "root\\CIMV2",
    "SELECT * FROM Win32_SystemDriver WHERE Name = \"PCAN_USB\"");

var isInstalled = (searcher.Get().Count > 0);
Best regards,
Keneth

sabinhagen
Posts: 6
Joined: Wed 19. Dec 2018, 03:29

Re: Way to Detect Device Driver

Post by sabinhagen » Fri 18. Jan 2019, 02:16

Thank you, Keneth, that worked perfectly!

Well, after I added the System.Management resource that is!

And just in case anyone else needs this feature, please note that the driver is NOT actually detected by simply installing the driver, but rather you also have to plug in the USB tool for the first time before the driver gets detected with this method. But I would consider that the last part of installing the driver.

Thanks again!

Post Reply