Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been using a WMI Query to detect when a new device has been detected, in this case a USB device. A Bluetooth dongle that creates a virtual comport.

The WMI Query string is "Select Name, Status from Win32_PnPEntity" for the Plug and Play entity.

This works great for me except for Windows 10, it cannot sense that the device has been inserted and therefore removed.

I have done a search for any changes to these queries but cannot find anything.

Does anyone know where I can find a list of the changes between the different operating systems?

Thanks
Posted
Comments
Nathan Minier 30-Oct-15 8:09am    
This might help:
http://stackoverflow.com/questions/29534970/using-managementobjectsearcher-to-query-win32-pnpentity-comes-back-empty

1 solution

I downloaded the WMI Code Creator and used it to get c# code for 'Win32_PnPEntity' using the name property.

In WMI Code creator lets you search for the property values for the name property and I did get a list for the USB device, however when I copied the code and put it in my program, it does not list the device that I want.

Both programs obviously run on the same OS and so I don't understand why it wont list the device in my program. The code below is what I extracted from WMI CC.


C#
using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_PnPEntity");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_PnPEntity instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Name: {0}", queryObj["Name"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}


Any ideas what this could be?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900