try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PnPEntity");
foreach (ManagementObject queryObj in searcher.Get())
{
if (queryObj["Caption"].ToString().Contains("(COM"))
{
comboBox1.Items.Add(queryObj["Name"]);
comboBox1.SelectedIndex=0;
textBox1.Text = Convert.ToString(comboBox1.SelectedItem);
textBox2.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 3);
}
}
}
catch (ManagementException )
{
MessageBox.Show("hata1");
}