我正在配对或连接到具有与之关联的串行端口服务的蓝牙设备。是否可以确定它注册的COM端口?如果是这样,怎么样?
答案 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;
}
}