Praveen Kumar

Praveen Kumar

  • 346
  • 6.2k
  • 1.9m

Win32_SerialPort Class not working in Windows 8.1 Pro

Apr 7 2021 4:46 AM
In Windows 8.1 Pro, the connected USB device list is not showing while USB device is showing into Device Manager(Control Panel).
 
I have a .NET 3.5 application, where I am using the following code to get the list of connected USB Serial Port device 
  1. ManagementObjectCollection collection;  
  2. using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"))  
  3. {  
  4.     string paytmUPIPort = "";  
  5.     collection = searcher.Get();  
  6.     foreach (var serialDevice in collection)  
  7.     {  
  8.         paytmUPIPort = string.Format("{0}", serialDevice.GetPropertyValue("DeviceID"));  
  9.         if(paytmUPIPort.ToUpper().Contains("COM"))  
  10.         {  
  11.             collection.Dispose();  
  12.             return paytmUPIPort;  
  13.         }  
  14.     }  
  15. }                  
  16. collection.Dispose();

Answers (1)