Reading Device Manager's Property Fields in Windows 7/8

前端 未结 3 1276
野性不改
野性不改 2021-02-09 17:42

I am developing a windows application which gives the field details --> X.

Where X is -->

Right Click My Computer >

    Properties >

                


        
相关标签:
3条回答
  • 2021-02-09 18:30

    It's quite easy to get the hardware information using ManagementObjectCollection.

    For instance to get all properties and values from the PC processor

    var win32DeviceClassName = "win32_processor";
                var query = string.Format("select * from {0}", win32DeviceClassName);
    
                using (var searcher = new ManagementObjectSearcher(query))
                {
                    ManagementObjectCollection  objectCollection = searcher.Get();
    
                    foreach (ManagementBaseObject managementBaseObject in objectCollection)
                    {
                        foreach (PropertyData propertyData in managementBaseObject.Properties)
                        {
                            Console.WriteLine("Property:  {0}, Value: {1}", propertyData.Name, propertyData.Value);
                        }
                    }
    
    
    
                }
    

    The full list of WIN32 class name is available at http://msdn.microsoft.com/en-us/library/aa394084%28v=VS.85%29.aspx

    Cheers.

    0 讨论(0)
  • 2021-02-09 18:42

    The question is tagged with C#, though the actual question asks for any Window API. With the Win32 API the information can be retrieved with SetupDiGetDeviceRegistryProperty(). The steps would be:

    1. Get a device info set for the devices you're interested in via SetupDiGetClassDevs().
    2. Iterate through the device infos via SetupDiEnumDeviceInfo().
    3. Get the properties via calls to SetupDiGetDeviceRegistryProperty().
    4. Destroy the device info set via SetupDiDestroyDeviceInfoList().

    According to the documentation the API is available on Windows 2000 and later.

    0 讨论(0)
  • 2021-02-09 18:44

    You're going to have the easiest time (I think) doing this with PowerShell. If you are writing some C# code you can execute a PS script using types in the System.Management.Automation namespace, such as PowerShell (link: http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx) but I would begin your testing using the PS Console.

    You should first (using PowerShell) explore the WMI objects in your environments using this command

    Get-WmiObject -List -namespace root\CIMV2
    

    Then once you identify with class you are looking for you can retrieve details on that class using this command:

    Get-WmiObject -namespace root\CIMV2 -class Win32_USBControllerDevice
    

    Once you have that content you'd have to parse the text.

    UPDATE: Try using this command to get the "State", "Status", and "Started" attributes of mouse drivers on your PC:

    gwmi Win32_SystemDriver | where {$_.DisplayName -like "*Mouse*"}
    
    0 讨论(0)
提交回复
热议问题