11

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.

Andi Jay
  • 5,882
  • 13
  • 51
  • 61
  • 1
    Not `c#`, but [Scripting Guy](http://blogs.technet.com/b/heyscriptingguy/archive/2006/03/20/how-can-i-get-a-list-of-installed-device-drivers.aspx) has some pointers that may help. And it's a Microsoft site, would you believe?! – icabod Apr 22 '13 at 16:49

2 Answers2

18

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.

Patrick D'Souza
  • 3,491
  • 2
  • 22
  • 39
  • Ok, I'm getting much closer with all this stuff you linked. My only question is, which of all the Win32 classes would let me see devices and driver versions? – Andi Jay Apr 22 '13 at 19:36
  • I'm calling this the answer. I still need to search through all the Win33 classes to see which will be able to give me devices and drivers though. – Andi Jay Apr 23 '13 at 13:33
  • I think thats the only one i could find having the properties you wanted. If there is any other, I would be glad to know. – Patrick D'Souza Apr 23 '13 at 14:57
  • You know what? That gets me all the devices I'm interested in! Thanks!!! This was A LOT of help, you don't understand how helpful this was! – Andi Jay Apr 23 '13 at 22:05
  • @AndiJay: A pleasure. It was a very interesting question too! I have added it as a favorite. – Patrick D'Souza Apr 24 '13 at 01:42
  • How can i get the status of a driver? – Rohit Paul Jul 10 '16 at 17:32
  • This is great. I have one question though, supose that i'm only interested in the main graphic card (NVIDIA something..) and processor (Intel Core i7 something...) how do i grab these devices without hardcoding the values so that my program can be used on any machine? – WhoAmI Mar 27 '19 at 21:29
  • You can also use [Win32_PnPEntity](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity) which contains the same properties. – Chiramisu Jan 20 '21 at 01:58
1

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]).

Nick
  • 2,593
  • 3
  • 30
  • 59
codedip
  • 191
  • 3
  • 11