0

I have to do port scanning with WMI. Is there a query for this? I tried the code I mentioned below, but it doesn't get into the loop:

 ManagementObjectCollection mReturn;
 ManagementObjectSearcher mSearch;
 mSearch = new ManagementObjectSearcher("SELECT * FROM Win32_SerialPort");
 mReturn = mSearch.Get();

 foreach (ManagementObject mObj in mReturn)
 {       
     listBox1.Items.Add(mObj["Name"].ToString());
 }
funie200
  • 3,688
  • 5
  • 21
  • 34
  • Does this answer your question? [WMI: Get list of all serial (COM) ports including virtual ports](https://stackoverflow.com/questions/45165299/wmi-get-list-of-all-serial-com-ports-including-virtual-ports) – Sinatr Jul 14 '20 at 09:34
  • Unfortunately no, I want to find out which ports are available – BERKAY KÜÇÜK Jul 14 '20 at 09:38
  • 1
    Looks like you have two issue 1) Finding com ports 2) Checking if they are being used. First we need to find out why you are not getting any results from query since you are not getting into the foreach loop. So my first question are the devices serial ports? – jdweng Jul 14 '20 at 11:11

0 Answers0