蓝牙串口设备检测COM端口#

时间:2009-08-31 18:54:31

标签: windows serial-port bluetooth

我正在配对或连接到具有与之关联的串行端口服务的蓝牙设备。是否可以确定它注册的COM端口?如果是这样,怎么样?

1 个答案:

答案 0 :(得分:0)

我刚刚发现以下C#WMI代码似乎可以完成这项工作。但这可靠吗?

        string deviceid = string.Empty;
        ManagementObjectSearcher searcher = new ManagementObjectSearcher ( "Select * from WIN32_SerialPort" );
        foreach ( ManagementObject port in searcher.Get () )
        {
            string name = port.GetPropertyValue ("Name" ) as string;
            string provider = port.GetPropertyValue ( "ProviderType" ) as string;
            if ( provider == null )
            {
                deviceid = port.GetPropertyValue ( "DeviceId" ) as string;
            }
        }