I am using WMI query to detect USB to serial port but the problem is that in windows 7 the application takes long time to start while in windows xp it is working fine. I am using wmi query in following way
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPDevice");
foreach (ManagementObject queryObj in searcher.Get())
{
if (queryObj["SameElement"].ToString().Contains("SerialPort"))
{
//do something
}
}
According to my reasoning it is happening due to large number of Pnp Devices and querying for serial port from that list. I tried using Win32_SerialPort but it working in windows xp while on my laptop(windows 7) it shows message not supported even though their are virtual serial port and USB to serial ports. It doesn't work even from administrator account. MSSerial_PortName also doesn't work on my laptop(windows7). Thus is their any way to make my application start faster in windows 7 using WMI query?