Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read devices and driver versions

Tags:

c#

.net

windows

I'm having a really hard time figuring out how to do this. Basically, all I want to do is read all the devices that are attached to the machine and also read the driver manufacturer and version of the device driver. This is the information you can get in the device manager,but I want to do it programattically.

I've done a lot of searching and reading, and can't find anything that helps me do this. There is this WMI stuff that should work, but I can't find any examples that work. I've read and read about WMI, but still can't figure it out.

Are there any tutorials out there that might explain WMI better than the Microsoft site? I need this to be down be to the crayola level.

like image 692
Andi Jay Avatar asked Apr 22 '13 16:04

Andi Jay


2 Answers

Please have a look at the following article

Get Your Hardware Information Using C#

Retrieving Information From Windows Management Instrumentation

EDIT:

I believe that you are looking for the following Win32_PnPSignedDriver class

public class Program
{
    public static void Main()
    {
        ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver");

        ManagementObjectCollection objCollection = objSearcher.Get();

        foreach (ManagementObject obj in objCollection)
        {
            string info = String.Format("Device='{0}',Manufacturer='{1}',DriverVersion='{2}' ", obj["DeviceName"], obj["Manufacturer"], obj["DriverVersion"]);
            Console.Out.WriteLine(info);
        }

        Console.Write("\n\nAny key...");
        Console.ReadKey();
    }
}

Aslo, if you are going to work a lot on WMI you might as well use this tool, to avoid creating test applications.

  • WMI Code Creator v1.0
like image 133
Patrick D'Souza Avatar answered Sep 20 '22 13:09

Patrick D'Souza


If you are looking for a specific kind of device information (suppose only Bluetooth) from your machine - then "ManagementObjectSearcher" in c# is good enough. You just need to include
using System.Management;
put a condition search with it as following

 ManagementObjectSearcher mos =
                   new ManagementObjectSearcher(@"\root\cimv2", @"Select * From Win32_PnPEntity WHERE ClassGuid = '"+deviceGuid+"'");

here "deviceGuid" is the device class type(a guid value [same for all PCs]).

like image 23
codedip Avatar answered Sep 20 '22 13:09

codedip