1

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

4

1 回答 1

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;
            }
        }
于 2009-08-31T22:11:20.210 回答