Q:

Using ManagementObjectSearcher to query Win32_PnPEntity comes back empty

OK, so this drives me nuts.
The code below worked just fine in Windows 7 with .NET 3.5.
In Windows 8.1 and .NET 4.5.1 I get an empty result, but using the WMI Code Creator I can get the results.
I cannot find anything about this online.
I want to get the friendly names of any COM ports, e.g. "Communications Port (COM1)".
Just using System.IO.Ports.SerialPort.GetPortNames() wont do.
I really hope someone know how to do this. Thanks!
using System;
using System.Collections.Generic;
using System.Management;

namespace OakHub
{
    public class SerialMgmt
    {
        static public List<String> GetCOMDevices()
        {
            List<String> list = new List<String>();

            ManagementScope scope = new ManagementScope(@"\\" + Environment.MachineName + @"\root\CIMV2");
            SelectQuery sq = new SelectQuery("SELECT Caption FROM Win32_PnPEntity");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, sq);
            ManagementObjectCollection moc = searcher.Get();

            foreach (ManagementObject mo in moc)
            {
                String name = mo.ToString();
                if (name.ToString().Contains("(COM"))
                {
                    list.Add(name);
                }
            }
            return list;
        }
    }
}

A:

First of all I dont know why this code is even working for you (with .Net 3.5).

You just selected the property Caption. (Use * to select all, if needed) 
I think you want the name of the Win32_PnPEntity-Devices, you cant get it with this line of code
String name = mo.ToString();
Because the Name is a property. You First have to load the Property with the WMI-String :
SELECT Name,Caption FROM Win32_PnPEntity //Get Name and Caption Property
or
SELECT * FROM Win32_PnPEntity //Load all the Propertys of that WMI-Obj

And than you have to check if value is null else --> return the value
Code:
public List<String> GetLocalCOMDevices()
        {
            List<String> list = new List<String>();

            ManagementScope scope = new ManagementScope(@"\\" + Environment.MachineName + @"\root\CIMV2");
            SelectQuery sq = new SelectQuery("SELECT Name,Caption FROM Win32_PnPEntity");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, sq);
            ManagementObjectCollection moc = searcher.Get();

            foreach (ManagementObject mo in moc)
            {
                object propName = mo.Properties["Name"].Value;
                if (propName == null) { continue; }

                list.Add(propName.ToString());
            }
            return list;
        }

