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.

1
  • 1
    Not c#, but Scripting Guy has some pointers that may help. And it's a Microsoft site, would you believe?!
    – icabod
    Commented Apr 22, 2013 at 16:49

2 Answers 2

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.

8
  • 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
    Commented Apr 22, 2013 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
    Commented Apr 23, 2013 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. Commented Apr 23, 2013 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
    Commented Apr 23, 2013 at 22:05
  • @AndiJay: A pleasure. It was a very interesting question too! I have added it as a favorite. Commented Apr 24, 2013 at 1:42
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]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.