0

enter image description here

This is what I get for installed software. I downloaded the Sixnet driver package and installed it. Now I want to detect if it has actually installed the drivers with the code below:

var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver");
foreach (ManagementObject obj in searcher.Get())
{
    //Looking for Sixnet USB Ethernet/RNDIS Gadget. Only try on objects that actually have a description.
    if (obj.GetPropertyValue("Description") != null)
    {
        try
        {
            if (obj.GetPropertyValue("Description").ToString().Contains("Sixnet USB Ethernet"))
            {
                return true;
            }
        }
        catch (Exception e)
        {

        }
    }
}
return false;

I am pretty sure it was returning true earlier today but now I cannot get this block to work, it does not detect the driver.

Lower down in the code I connect to the NIC and that works but it was my understanding that it would only connect to the NIC if the driver was actually installed because the default driver does not work.

Below is my network connections and I can see the modem as Network 5 - the one with Sixnet in the name. Why does my code not want to show that the drivers are installed? I want to run the software to first check if the drivers were installed and then if I can connect to the Sixnet modem via a USB cable. Thank you

enter image description here

Edit: Ok, I changed obj.GetPropertyValue("Description") to obj.GetPropertyValue("Devicename") and it did not work immediately so I moved on to other work and 10 minutes later it worked? How do I refresh the WMI database?

Edit #2:

    private bool Check_Drivers()
    {
        var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver where DeviceName LIKE '%Sixnet USB%'");
        if (searcher.Get().Count > 0)
        {
            searcher = null;
            return true;
        }
        searcher = null;
        return false;
    }

I changed my whole method to the code above. The searcher = null; was my attempt to make sure every call to this method reloads the management object.

Jack Smit
  • 3,093
  • 4
  • 30
  • 45
  • Why are you ignoring exceptions? – John Saunders Feb 08 '14 at 03:35
  • Ignoring exceptions, where? I do not understand where you get that.... – Jack Smit Feb 08 '14 at 03:37
  • `try { ... } catch (Exception e) {}` – John Saunders Feb 08 '14 at 12:05
  • John, thanks for your response. I found that sometimes oj.GetPropertyValue("Description") would be not exist - I had some code that I have not removed, the method is now. I will add it as an edit. Is there some reason why the WMI database would become stale? – Jack Smit Feb 09 '14 at 02:18
  • private bool Check_Drivers() { var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver where DeviceName LIKE '%Sixnet USB%'"); if (searcher.Get().Count > 0) { searcher = null; return true; } searcher = null; return false; } I changed my whole method to the code above. The searcher = null; was my attempt to make sure every call to this method reloads the management object. – Jack Smit Feb 09 '14 at 02:21
  • Add that to the question at the bottom. – John Saunders Feb 09 '14 at 02:22
  • Did that under Edit #2 - sorry. This is killing me!!! It all worked when I went to bed last night, I started my laptop just now and the Check_Drivers does not detect my drivers, whaddup? – Jack Smit Feb 09 '14 at 02:26

0 Answers0