How to read devices and driver versions

前端 未结 2 530
醉话见心
醉话见心 2021-01-02 06:54

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 man

相关标签:
2条回答
  • 2021-01-02 07:07

    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
    0 讨论(0)
  • 2021-01-02 07:07

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

    0 讨论(0)
提交回复
热议问题