Eu bati na mesma parede hoje. Isso funciona para mim temporariamente ...
catch (ManagementException ex)
{
Debug.WriteLine( string.Format( "##DBG An error occurred while querying for WMI data to find available COM ports:\n Message: {0}\n Stacktrace: {1}", ex.Message, ex.StackTrace) );
bool bSucceed = true;
// TODO Q&D solutions. As it does not work as expected (on windows 7 ) we create our ow default list here and check if we can open the ports
for (int x = 1; x <= 9; x++)
{
bSucceed = true;
cComportName = string.Format("COM{0}", x);
/////////////////////
// Check if we can open it here
// Set the port's settings
m_comport.BaudRate = 9600;
m_comport.DataBits = 8; // int.Parse(cmbDataBits.Text);
m_comport.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "1" );
m_comport.Parity = (Parity)Enum.Parse(typeof(Parity), "None" );
m_comport.PortName = cComportName;
try
{
// Open the port
m_comport.Open();
}
catch (UnauthorizedAccessException) { bSucceed = false; }
catch (IOException) { bSucceed = false; }
catch (ArgumentException) { bSucceed = false; }
if (bSucceed)
{
m_comport.Close();
m_listComPorts.Add(new string[ConstComPortAttr.COMPORT_MAX_COLUMNS] { cComportName, cInstanceName });
}
}