1
Answer

Checking for a Driver Version

Glenn Patton

Glenn Patton

12y
1.4k
1
Hi All,

I need to check a driver version I have asked this on MSDN & The Code Project and each time got answers that I don't really understand.  I want to check the version of a driver installed if it is not there install it, if it is there which version if it later than the version I am using leave it, if not update it. 
I have so far managed to get the below code:

    ServiceController[] scDevices = ServiceController.GetDevices();

      private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Device driver services on the local computer");

            foreach (ServiceController scTemp in scDevices)
            {
                lstDrivers.Items.Add(scTemp.ServiceType + "," + scTemp.ServiceName + "," + scTemp.DisplayName);                          
            }

           
        }
This puts into a list box all the drivers installed on the machine I can see the driver I want and that appears to be all I can do, the Code Project have supplied a Dictionary based bit of code which I am at a loss on how to populate and use at <http://www.codeproject.com/Messages/4299056/Re-Continuation-of-Correct-way-of-doing-installers.aspx> I really want a method that can be run while the program is being is installed and when the program is run to avoid the wheels coming off due to a missing or over written driver.
Thanks

Glenn  

Answers (1)
0
Glenn Patton

Glenn Patton

NA 333 60.7k 12y
Hi All,

I have managed to get the correct version of the driver I need here is the code to do it!
 private void button5_Click(object sender, EventArgs e)
        {
     
            List<SignedDriver> drivers = GetDriverInfo();
          
            foreach (SignedDriver driver in drivers)
                listBox1.Items.Add(driver.DeviceName+","+driver.DriverDate+","+driver.DriverVersion);
        
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int index = -1;
          
            index = listBox1.FindString("USB Serial Converter,20120410000000.******+***");
            if (index == -1)
            {
                MessageBox.Show(" Driver Not Found ","",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("index = " + index.ToString() + " , " + listBox1.Items[index].ToString(),"",MessageBoxButtons.OK,MessageBoxIcon.Information);
                textBox2.Text = listBox1.Items[index].ToString();
            }




        }

        private void button7_Click(object sender, EventArgs e)
        {
            const char Comma = ',';
            string Target;
            string Version_Number = "";
            string output = "";
            int count = 0;

           
            Target = textBox2.Text;

          
            foreach (string subString in Target.Split(Comma))
            {
                output += subString + ";";
                count++;
                if(count == 3)
                {
                    Version_Number = subString;
                    break;
                }

           }

            MessageBox.Show("Version of driver is "+Version_Number,"",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

       

    }
 That took a lot of doing to find out the how and why, the Service Controller method will not allow the info I needed (I hope!)
Glenn