2009-08-31 78 views

回答

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; 
      } 
     }