常用的两种方法
方法一:
view plaincopy to clipboardprint?
using Microsoft.Win32;  
 
 RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");  
            if (keyCom != null)  
            {  
                string[] sSubKeys = keyCom.GetValueNames();  
                foreach (string sName in sSubKeys)  
                {  
                    string sValue = (string)keyCom.GetValue(sName);  
                    this.textBox1.Text = this.textBox1.Text + sValue + "\r\n";  
                }  
            } 
using Microsoft.Win32;
 RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
            if (keyCom != null)
            {
                string[] sSubKeys = keyCom.GetValueNames();
                foreach (string sName in sSubKeys)
                {
                    string sValue = (string)keyCom.GetValue(sName);
                    this.textBox1.Text = this.textBox1.Text + sValue + "\r\n";
                }
            }
方法二:
view plaincopy to clipboardprint?
using System.IO.Ports;  
 
foreach (string vPortName in SerialPort.GetPortNames())  
{  
    this.textBox2.Text = this.textBox2.Text + vPortName + "\r\n";