using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Management;
using System.Management.Instrumentation;
using Microsoft.Win32;
using System.Diagnostics;
namespace GetSerailPort
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ManagementObjectCollection mObjCol;
ManagementObjectSearcher mObjSearch;
mObjSearch = new ManagementObjectSearcher("Select * from Win32_PnPEntity");
mObjCol = mObjSearch.Get();
foreach (ManagementObject mObj in mObjCol)
{
if (mObj["ClassGUID"].ToString() == "{4D36E978-E325-11CE-BFC1-08002BE10318}")
{
listBox1.Items.Add(mObj["Name"].ToString());
}
}
}
}
}