c#获得串口列表

之前从网上当到的,从注册表里面获取

C#获取串口列表
      //using Microsoft.Win32;
        public void GetComList()
        {
            RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
            if (keyCom != null)
            {
                string[] sSubKeys = keyCom.GetValueNames();
                this.cmbComPort.Items.Clear();
                foreach (string sName in sSubKeys)
                {
                    string sValue = (string)keyCom.GetValue(sName);
                    this.cmbComPort.Items.Add(sValue);
                }
            }
        }

posted @ 2016-01-09 23:13  六芒兔工业物联  阅读(753)  评论(0编辑  收藏  举报