c#——动态获取本机可用串口

private void GetSerialPort()   //获取串口列表                                             
{
    RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
    if (keyCom != null)
    {
        this.comBoxEdit1.properties.Items.clear();
        string[] sSubKeys = keyCom.GetValueNames();
        foreach (string sName in sSubKeys)
        {
            string sValue = (string)keyCom.GetValue(sName);
            this.comBoxEdit1.properties.Add(sValue);
        }
        comBoxEdit1.SelectedIndex = 0;
    }
}

你可能感兴趣的:(c#)